From b45da67f91b12b99679890e088a772274a4638eb Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Nov 2024 09:08:04 +0800 Subject: [PATCH 1/2] Use PHPStan 1 Signed-off-by: Mior Muhammad Zaki --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b6c561d..d1e5e71 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "guzzlehttp/guzzle": "^7.3", "laravel/framework": "^7.20|^8.19", "orchestra/testbench-core": "^5.0|^6.0", - "phpstan/phpstan": "^0.12.93", + "phpstan/phpstan": "^1.11", "phpunit/phpunit": "^9.3", "spatie/phpunit-snapshot-assertions": "^4.2" }, From 0450cc51104394404ed73863e2a29b4ae2854bb0 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 12 Nov 2024 09:16:22 +0800 Subject: [PATCH 2/2] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/phpstan.yml | 2 +- phpstan.neon.dist | 6 ------ src/OriginFactory.php | 4 ++-- src/RayServiceProvider.php | 8 ++++---- src/Watchers/CacheWatcher.php | 1 + src/Watchers/DuplicateQueryWatcher.php | 1 + src/Watchers/EventWatcher.php | 1 + src/Watchers/ExceptionWatcher.php | 1 + src/Watchers/HttpClientWatcher.php | 2 ++ src/Watchers/JobWatcher.php | 1 + src/Watchers/QueryWatcher.php | 1 + src/Watchers/RequestWatcher.php | 5 +++-- src/Watchers/SlowQueryWatcher.php | 1 + src/Watchers/ViewWatcher.php | 1 + 14 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index a552d04..95de501 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -18,4 +18,4 @@ jobs: uses: ramsey/composer-install@v3 - name: Run PHPStan - run: vendor/bin/phpstan --error-format=github + run: vendor/bin/phpstan --error-format=github --verbose diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2c029ab..c5e840f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,9 +11,3 @@ parameters: - '#^Call to method \w+\(\) on an unknown class Spatie\\WordPressRay\\Ray\.$#' - '#^Call to method \w+\(\) on an unknown class Spatie\\RayBundle\\Ray\.$#' - '#^Access to an undefined property Spatie\\Ray\\Settings\\Settings\:\:\$\w+\.$#' - - - message: '#^Access to an undefined property Spatie\\LaravelRay\\RayServiceProvider\:\:\$items\.$#' - path: src/RayServiceProvider.php - - - message: '#^Access to an undefined property Spatie\\LaravelRay\\RayServiceProvider\:\:\$value\.$#' - path: src/RayServiceProvider.php diff --git a/src/OriginFactory.php b/src/OriginFactory.php index 0d29864..28d2de4 100644 --- a/src/OriginFactory.php +++ b/src/OriginFactory.php @@ -29,8 +29,8 @@ public function getOrigin(): Origin $frame = $this->getFrame(); return new Origin( - optional($frame)->file, - optional($frame)->lineNumber, + optional($frame)->file, // @phpstan-ignore property.notFound + optional($frame)->lineNumber, // @phpstan-ignore property.notFound ); } diff --git a/src/RayServiceProvider.php b/src/RayServiceProvider.php index 489185c..a82b102 100644 --- a/src/RayServiceProvider.php +++ b/src/RayServiceProvider.php @@ -191,8 +191,8 @@ protected function registerMacros(): self { Collection::macro('ray', function (string $description = '') { $description === '' - ? ray($this->items) - : ray($description, $this->items); + ? ray($this->items) // @phpstan-ignore property.protected + : ray($description, $this->items); // @phpstan-ignore property.protected return $this; }); @@ -206,8 +206,8 @@ protected function registerMacros(): self Stringable::macro('ray', function (string $description = '') { $description === '' - ? ray($this->value) - : ray($description, $this->value); + ? ray($this->value) // @phpstan-ignore property.protected + : ray($description, $this->value); // @phpstan-ignore property.protected return $this; }); diff --git a/src/Watchers/CacheWatcher.php b/src/Watchers/CacheWatcher.php index 87aeaae..bfeb1d7 100644 --- a/src/Watchers/CacheWatcher.php +++ b/src/Watchers/CacheWatcher.php @@ -27,6 +27,7 @@ public function register(): void $ray = $this->ray()->sendRequest($payload); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); diff --git a/src/Watchers/DuplicateQueryWatcher.php b/src/Watchers/DuplicateQueryWatcher.php index b1ae461..6972d6a 100644 --- a/src/Watchers/DuplicateQueryWatcher.php +++ b/src/Watchers/DuplicateQueryWatcher.php @@ -40,6 +40,7 @@ public function register(): void $ray = app(Ray::class)->sendRequest($payload); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/EventWatcher.php b/src/Watchers/EventWatcher.php index 80564e9..0b623b2 100644 --- a/src/Watchers/EventWatcher.php +++ b/src/Watchers/EventWatcher.php @@ -19,6 +19,7 @@ public function register(): void $ray = app(Ray::class)->sendRequest($payload); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/ExceptionWatcher.php b/src/Watchers/ExceptionWatcher.php index b417dfb..42b949f 100644 --- a/src/Watchers/ExceptionWatcher.php +++ b/src/Watchers/ExceptionWatcher.php @@ -63,6 +63,7 @@ public function getFlareReport(Throwable $exception): ?array if (app()->bound(Flare::class)) { $flare = app(Flare::class); + /** @phpstan-ignore class.notFound */ $report = $flare->createReport($exception); return (new ReportTrimmer())->trim($report->toArray()); diff --git a/src/Watchers/HttpClientWatcher.php b/src/Watchers/HttpClientWatcher.php index 2ceaab0..8d1e283 100644 --- a/src/Watchers/HttpClientWatcher.php +++ b/src/Watchers/HttpClientWatcher.php @@ -30,6 +30,7 @@ public function register(): void $ray = $this->handleRequest($event->request); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); @@ -40,6 +41,7 @@ public function register(): void $ray = $this->handleResponse($event->request, $event->response); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/JobWatcher.php b/src/Watchers/JobWatcher.php index 394bb95..9b4816c 100644 --- a/src/Watchers/JobWatcher.php +++ b/src/Watchers/JobWatcher.php @@ -33,6 +33,7 @@ public function register(): void $ray = app(Ray::class)->sendRequest($payload); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/QueryWatcher.php b/src/Watchers/QueryWatcher.php index 7a8efef..cd82e4d 100644 --- a/src/Watchers/QueryWatcher.php +++ b/src/Watchers/QueryWatcher.php @@ -43,6 +43,7 @@ public function register(): void $ray = app(Ray::class)->sendRequest($payload); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/RequestWatcher.php b/src/Watchers/RequestWatcher.php index 60cc90e..770ccd4 100644 --- a/src/Watchers/RequestWatcher.php +++ b/src/Watchers/RequestWatcher.php @@ -30,6 +30,7 @@ public function register(): void $ray = $this->handleRequest($event->request, $event->response); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } @@ -54,8 +55,8 @@ protected function handleRequest(Request $request, Response $response): Ray 'IP Address' => $request->ip(), 'URI' => str_replace($request->root(), '', $request->fullUrl()) ?: '/', 'Method' => $request->method(), - 'Controller action' => optional($request->route())->getActionName(), - 'Middleware' => array_values(optional($request->route())->gatherMiddleware() ?? []), + 'Controller action' => optional($request->route())->getActionName(), // @phpstan-ignore method.notFound + 'Middleware' => array_values(optional($request->route())->gatherMiddleware() ?? []), // @phpstan-ignore method.notFound 'Headers' => $headers, 'Payload' => $this->payload($request), 'Session' => $session, diff --git a/src/Watchers/SlowQueryWatcher.php b/src/Watchers/SlowQueryWatcher.php index ce0f880..05d6dff 100644 --- a/src/Watchers/SlowQueryWatcher.php +++ b/src/Watchers/SlowQueryWatcher.php @@ -32,6 +32,7 @@ public function register(): void $ray->sendRequest($payload); } + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); } diff --git a/src/Watchers/ViewWatcher.php b/src/Watchers/ViewWatcher.php index ef65713..a95158a 100644 --- a/src/Watchers/ViewWatcher.php +++ b/src/Watchers/ViewWatcher.php @@ -24,6 +24,7 @@ public function register(): void $ray = app(Ray::class)->view($view); + /** @phpstan-ignore method.notFound */ optional($this->rayProxy)->applyCalledMethods($ray); }); }