From 71461ecaa7a3e29b6d6edde7d1fa39bddcca8794 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 12 Jun 2024 12:06:04 +0200 Subject: [PATCH 1/7] Refactor solutions --- src/FlareMiddleware/AddSolutions.php | 7 ++++--- src/Report.php | 10 ++++++---- src/Solutions/ReportSolution.php | 14 ++++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/FlareMiddleware/AddSolutions.php b/src/FlareMiddleware/AddSolutions.php index cc53293..d7426eb 100644 --- a/src/FlareMiddleware/AddSolutions.php +++ b/src/FlareMiddleware/AddSolutions.php @@ -4,13 +4,14 @@ use Closure; use Spatie\FlareClient\Report; -use Spatie\Ignition\Contracts\SolutionProviderRepository; +use Spatie\ErrorSolutions\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..fbd479c 100644 --- a/src/Report.php +++ b/src/Report.php @@ -13,8 +13,10 @@ 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\ErrorSolutions\Contracts\Solution; +use Spatie\Ignition\Contracts\Solution as IgnitionSolution; +use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException; +use Spatie\LaravelFlare\Exceptions\ViewException; 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..ae1c71f 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\Ignition\Contracts\RunnableSolution as IgnitionRunnableSolution; +use Spatie\Ignition\Contracts\Solution as IgnitionSolution; +use Spatie\ErrorSolutions\Contracts\RunnableSolution; +use Spatie\ErrorSolutions\Contracts\Solution; 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), From 82926f46d7152c436c22f532c3ac49ea1be61b14 Mon Sep 17 00:00:00 2001 From: rubenvanassche Date: Wed, 12 Jun 2024 10:06:36 +0000 Subject: [PATCH 2/7] Fix styling --- src/FlareMiddleware/AddSolutions.php | 2 +- src/Report.php | 4 ++-- src/Solutions/ReportSolution.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FlareMiddleware/AddSolutions.php b/src/FlareMiddleware/AddSolutions.php index d7426eb..5ad9997 100644 --- a/src/FlareMiddleware/AddSolutions.php +++ b/src/FlareMiddleware/AddSolutions.php @@ -3,8 +3,8 @@ namespace Spatie\FlareClient\FlareMiddleware; use Closure; -use Spatie\FlareClient\Report; use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository; +use Spatie\FlareClient\Report; use Spatie\Ignition\Contracts\SolutionProviderRepository as IgnitionSolutionProviderRepository; class AddSolutions implements FlareMiddleware diff --git a/src/Report.php b/src/Report.php index fbd479c..6f0822f 100644 --- a/src/Report.php +++ b/src/Report.php @@ -7,16 +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\ErrorSolutions\Contracts\Solution; use Spatie\Ignition\Contracts\Solution as IgnitionSolution; -use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException; use Spatie\LaravelFlare\Exceptions\ViewException; +use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException; use Throwable; class Report diff --git a/src/Solutions/ReportSolution.php b/src/Solutions/ReportSolution.php index ae1c71f..22c024d 100644 --- a/src/Solutions/ReportSolution.php +++ b/src/Solutions/ReportSolution.php @@ -2,10 +2,10 @@ namespace Spatie\FlareClient\Solutions; -use Spatie\Ignition\Contracts\RunnableSolution as IgnitionRunnableSolution; -use Spatie\Ignition\Contracts\Solution as IgnitionSolution; 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 { From 145eee98cf9a6cd4ca0c242c0a4325c50d9083cf Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 12 Jun 2024 12:09:36 +0200 Subject: [PATCH 3/7] Fix PHPStan --- phpstan-baseline.neon | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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 From 5a6d15e579967411bc716e417c095dd2d72bf8db Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 12 Jun 2024 16:05:25 +0200 Subject: [PATCH 4/7] Update dependency --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 3f156176a1af963987aff0ba7df688cdfda2d51f Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 12 Jun 2024 16:27:37 +0200 Subject: [PATCH 5/7] Add support for fixing stack trace arguments ini paramater --- src/Flare.php | 11 +++++++-- src/Support/PhpStackFrameArgumentsFixer.php | 24 +++++++++++++++++++ .../PhpStackFrameArgumentsFixerTest.php | 24 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/Support/PhpStackFrameArgumentsFixer.php create mode 100644 tests/Support/PhpStackFrameArgumentsFixerTest.php 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/Support/PhpStackFrameArgumentsFixer.php b/src/Support/PhpStackFrameArgumentsFixer.php new file mode 100644 index 0000000..e02044f --- /dev/null +++ b/src/Support/PhpStackFrameArgumentsFixer.php @@ -0,0 +1,24 @@ +isCurrentlyIgnoringStackFrameArguments()) { + return; + } + + ini_set('zend.exception_ignore_args', false); + } + + 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..04bcb00 --- /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); +}); From d6882cda0cb5f7b2739048063d4b4b6e2cdedccf Mon Sep 17 00:00:00 2001 From: rubenvanassche Date: Wed, 12 Jun 2024 14:28:04 +0000 Subject: [PATCH 6/7] Fix styling --- tests/Support/PhpStackFrameArgumentsFixerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Support/PhpStackFrameArgumentsFixerTest.php b/tests/Support/PhpStackFrameArgumentsFixerTest.php index 04bcb00..98cc29b 100644 --- a/tests/Support/PhpStackFrameArgumentsFixerTest.php +++ b/tests/Support/PhpStackFrameArgumentsFixerTest.php @@ -3,7 +3,7 @@ use Spatie\FlareClient\Flare; use Spatie\FlareClient\Tests\TestClasses\TraceArguments; -it('can enable stack trace arguments on a PHP level', function (){ +it('can enable stack trace arguments on a PHP level', function () { ini_set('zend.exception_ignore_args', 1); $report = Flare::make() From 75b8997699ce8b158b2bc76dce75f4ddeb8bd578 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 12 Jun 2024 16:37:00 +0200 Subject: [PATCH 7/7] Force stack frame arguments --- src/Support/PhpStackFrameArgumentsFixer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/PhpStackFrameArgumentsFixer.php b/src/Support/PhpStackFrameArgumentsFixer.php index e02044f..ef598ad 100644 --- a/src/Support/PhpStackFrameArgumentsFixer.php +++ b/src/Support/PhpStackFrameArgumentsFixer.php @@ -10,7 +10,7 @@ public function enable(): void return; } - ini_set('zend.exception_ignore_args', false); + ini_set('zend.exception_ignore_args', '0'); } protected function isCurrentlyIgnoringStackFrameArguments(): bool