diff --git a/composer.json b/composer.json index 3bd74fa..5326cd3 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^8.0", "illuminate/pipeline": "^8.0|^9.0|^10.0|^11.0", - "spatie/backtrace": "^1.5.2", + "spatie/backtrace": "^1.6.1", "symfony/http-foundation": "^5.2|^6.0|^7.0", "symfony/mime": "^5.2|^6.0|^7.0", "symfony/process": "^5.2|^6.0|^7.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 518d3a4..79a08e1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,6 +10,11 @@ parameters: count: 1 path: src/Glows/Glow.php + - + message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Report\\:\\:addSolution\\(\\) has invalid type Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Report.php + - message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Report\\:\\:addSolution\\(\\) has invalid type Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 @@ -20,41 +25,81 @@ parameters: count: 1 path: src/Report.php + - + message: "#^Access to property \\$aiGenerated on an unknown class Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Access to property \\$aiGenerated on an unknown class Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Call to method getDocumentationLinks\\(\\) on an unknown class Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Call to method getDocumentationLinks\\(\\) on an unknown class Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Call to method getSolutionDescription\\(\\) on an unknown class Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Call to method getSolutionDescription\\(\\) on an unknown class Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Call to method getSolutionTitle\\(\\) on an unknown class Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Call to method getSolutionTitle\\(\\) on an unknown class Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Class Spatie\\\\ErrorSolutions\\\\Contracts\\\\RunnableSolution not found\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Class Spatie\\\\Ignition\\\\Contracts\\\\RunnableSolution not found\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:__construct\\(\\) has invalid type Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:__construct\\(\\) has invalid type Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:fromSolution\\(\\) has invalid type Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Parameter \\$solution of method Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:fromSolution\\(\\) has invalid type Spatie\\\\Ignition\\\\Contracts\\\\Solution\\.$#" count: 1 path: src/Solutions/ReportSolution.php + - + message: "#^Property Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:\\$solution has unknown class Spatie\\\\ErrorSolutions\\\\Contracts\\\\Solution as its type\\.$#" + count: 1 + path: src/Solutions/ReportSolution.php + - message: "#^Property Spatie\\\\FlareClient\\\\Solutions\\\\ReportSolution\\:\\:\\$solution has unknown class Spatie\\\\Ignition\\\\Contracts\\\\Solution as its type\\.$#" count: 1 diff --git a/src/Flare.php b/src/Flare.php index 2276e6d..f6ac298 100755 --- a/src/Flare.php +++ b/src/Flare.php @@ -21,6 +21,7 @@ use Spatie\FlareClient\Glows\Glow; use Spatie\FlareClient\Glows\GlowRecorder; use Spatie\FlareClient\Http\Client; +use Spatie\FlareClient\Support\PhpStackFrameArgumentsFixer; use Throwable; class Flare @@ -145,10 +146,16 @@ public function argumentReducers(null|array|ArgumentReducers $argumentReducers): return $this; } - public function withStackFrameArguments(bool $withStackFrameArguments = true): self - { + public function withStackFrameArguments( + bool $withStackFrameArguments = true, + bool $forcePHPIniSetting = false, + ): self { $this->withStackFrameArguments = $withStackFrameArguments; + if ($forcePHPIniSetting) { + (new PhpStackFrameArgumentsFixer())->enable(); + } + return $this; } diff --git a/src/FlareMiddleware/AddSolutions.php b/src/FlareMiddleware/AddSolutions.php index cc53293..5ad9997 100644 --- a/src/FlareMiddleware/AddSolutions.php +++ b/src/FlareMiddleware/AddSolutions.php @@ -3,14 +3,15 @@ namespace Spatie\FlareClient\FlareMiddleware; use Closure; +use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository; use Spatie\FlareClient\Report; -use Spatie\Ignition\Contracts\SolutionProviderRepository; +use Spatie\Ignition\Contracts\SolutionProviderRepository as IgnitionSolutionProviderRepository; class AddSolutions implements FlareMiddleware { - protected SolutionProviderRepository $solutionProviderRepository; + protected SolutionProviderRepository|IgnitionSolutionProviderRepository $solutionProviderRepository; - public function __construct(SolutionProviderRepository $solutionProviderRepository) + public function __construct(SolutionProviderRepository|IgnitionSolutionProviderRepository $solutionProviderRepository) { $this->solutionProviderRepository = $solutionProviderRepository; } diff --git a/src/Report.php b/src/Report.php index 783260e..6f0822f 100644 --- a/src/Report.php +++ b/src/Report.php @@ -7,14 +7,16 @@ use Spatie\Backtrace\Arguments\Reducers\ArgumentReducer; use Spatie\Backtrace\Backtrace; use Spatie\Backtrace\Frame as SpatieFrame; +use Spatie\ErrorSolutions\Contracts\Solution; use Spatie\FlareClient\Concerns\HasContext; use Spatie\FlareClient\Concerns\UsesTime; use Spatie\FlareClient\Context\ContextProvider; use Spatie\FlareClient\Contracts\ProvidesFlareContext; use Spatie\FlareClient\Glows\Glow; use Spatie\FlareClient\Solutions\ReportSolution; -use Spatie\Ignition\Contracts\Solution; -use Spatie\LaravelIgnition\Exceptions\ViewException; +use Spatie\Ignition\Contracts\Solution as IgnitionSolution; +use Spatie\LaravelFlare\Exceptions\ViewException; +use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException; use Throwable; class Report @@ -95,7 +97,7 @@ public static function createForThrowable( protected static function getClassForThrowable(Throwable $throwable): string { /** @phpstan-ignore-next-line */ - if ($throwable::class === ViewException::class) { + if ($throwable::class === IgnitionViewException::class || $throwable::class === ViewException::class) { /** @phpstan-ignore-next-line */ if ($previous = $throwable->getPrevious()) { return get_class($previous); @@ -259,7 +261,7 @@ public function addGlow(Glow $glow): self return $this; } - public function addSolution(Solution $solution): self + public function addSolution(Solution|IgnitionSolution $solution): self { $this->solutions[] = ReportSolution::fromSolution($solution)->toArray(); diff --git a/src/Solutions/ReportSolution.php b/src/Solutions/ReportSolution.php index 4291dc4..22c024d 100644 --- a/src/Solutions/ReportSolution.php +++ b/src/Solutions/ReportSolution.php @@ -2,19 +2,21 @@ namespace Spatie\FlareClient\Solutions; -use Spatie\Ignition\Contracts\RunnableSolution; -use Spatie\Ignition\Contracts\Solution as SolutionContract; +use Spatie\ErrorSolutions\Contracts\RunnableSolution; +use Spatie\ErrorSolutions\Contracts\Solution; +use Spatie\Ignition\Contracts\RunnableSolution as IgnitionRunnableSolution; +use Spatie\Ignition\Contracts\Solution as IgnitionSolution; class ReportSolution { - protected SolutionContract $solution; + protected Solution|IgnitionSolution $solution; - public function __construct(SolutionContract $solution) + public function __construct(Solution|IgnitionSolution $solution) { $this->solution = $solution; } - public static function fromSolution(SolutionContract $solution): self + public static function fromSolution(Solution|IgnitionSolution $solution): self { return new self($solution); } @@ -24,7 +26,7 @@ public static function fromSolution(SolutionContract $solution): self */ public function toArray(): array { - $isRunnable = ($this->solution instanceof RunnableSolution); + $isRunnable = ($this->solution instanceof RunnableSolution || $this->solution instanceof IgnitionRunnableSolution); return [ 'class' => get_class($this->solution), diff --git a/src/Support/PhpStackFrameArgumentsFixer.php b/src/Support/PhpStackFrameArgumentsFixer.php new file mode 100644 index 0000000..ef598ad --- /dev/null +++ b/src/Support/PhpStackFrameArgumentsFixer.php @@ -0,0 +1,24 @@ +isCurrentlyIgnoringStackFrameArguments()) { + return; + } + + ini_set('zend.exception_ignore_args', '0'); + } + + protected function isCurrentlyIgnoringStackFrameArguments(): bool + { + return match (ini_get('zend.exception_ignore_args')) { + '1' => true, + '0' => false, + default => false, + }; + } +} diff --git a/tests/Support/PhpStackFrameArgumentsFixerTest.php b/tests/Support/PhpStackFrameArgumentsFixerTest.php new file mode 100644 index 0000000..98cc29b --- /dev/null +++ b/tests/Support/PhpStackFrameArgumentsFixerTest.php @@ -0,0 +1,24 @@ +withStackFrameArguments(true, forcePHPIniSetting: false) + ->createReport(TraceArguments::create()->exception('string', new DateTime())) + ->toArray(); + + expect($report['stacktrace'][1]['arguments'])->toBeNull(); + + $report = Flare::make() + ->withStackFrameArguments(true, forcePHPIniSetting: true) + ->createReport(TraceArguments::create()->exception('string', new DateTime())) + ->toArray(); + + expect($report['stacktrace'][1]['arguments']) + ->toBeArray() + ->toHaveCount(2); +});