From fe112f872fe1ba90ed2be3dd30aa6ac529e9b558 Mon Sep 17 00:00:00 2001 From: lubiana Date: Mon, 7 Nov 2022 17:16:33 +0100 Subject: [PATCH] fix phpstan errors --- app/src/Infrastructure/Event/DispatcherFactory.php | 8 +++++--- app/src/Infrastructure/Finder.php | 8 +++++++- app/src/Infrastructure/Route/Handler.php | 2 +- app/src/Infrastructure/WebApp/Route/CachedResponse.php | 3 ++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/Infrastructure/Event/DispatcherFactory.php b/app/src/Infrastructure/Event/DispatcherFactory.php index 08ba7e9..81960d7 100644 --- a/app/src/Infrastructure/Event/DispatcherFactory.php +++ b/app/src/Infrastructure/Event/DispatcherFactory.php @@ -32,10 +32,12 @@ final class DispatcherFactory private function getListeners(bool $cached = false): array { if ($cached === true && file_exists(self::CACHE_FILE)) { + $data = file_get_contents(self::CACHE_FILE); + if ($data === false) { + return []; + } /** @var Listener[] $listeners */ - $listeners = unserialize( - file_get_contents(self::CACHE_FILE) - ); //@phpstan-ignore-line + $listeners = unserialize($data); return $listeners; } diff --git a/app/src/Infrastructure/Finder.php b/app/src/Infrastructure/Finder.php index 623fc28..4fa4a06 100644 --- a/app/src/Infrastructure/Finder.php +++ b/app/src/Infrastructure/Finder.php @@ -68,7 +68,13 @@ final class Finder } if ($this->cached === true && file_exists(self::CACHE_FILE)) { - $this->classNames = unserialize(file_get_contents(self::CACHE_FILE)); + $data = file_get_contents(self::CACHE_FILE); + if ($data === false) { + return; + } + /** @var class-string[] $result */ + $result = unserialize($data); + $this->classNames = $result; return; } diff --git a/app/src/Infrastructure/Route/Handler.php b/app/src/Infrastructure/Route/Handler.php index 0e97b19..a1a02f0 100644 --- a/app/src/Infrastructure/Route/Handler.php +++ b/app/src/Infrastructure/Route/Handler.php @@ -5,7 +5,7 @@ namespace Lubian\AttributeMagic\Infrastructure\Route; final class Handler { /** - * @param non-empty-string $path + * @param string $path * @param non-empty-string $handlerClass * @param non-empty-string $handlerMethod */ diff --git a/app/src/Infrastructure/WebApp/Route/CachedResponse.php b/app/src/Infrastructure/WebApp/Route/CachedResponse.php index d2d19e6..7b1983e 100644 --- a/app/src/Infrastructure/WebApp/Route/CachedResponse.php +++ b/app/src/Infrastructure/WebApp/Route/CachedResponse.php @@ -18,9 +18,10 @@ final class CachedResponse { $response = new Response('lol'); $serialized = serialize($response); + /** @var Response|null $response */ $response = unserialize($serialized); $event->response = $response; - // $event->stopped = true; + $event->stopped = true; } #[AsListener(RequestEvent::class, 99)]