From adf47ca451415aa25bab6ae7feb9ccf42f64ffc7 Mon Sep 17 00:00:00 2001 From: Alex Vanderbist Date: Fri, 26 Aug 2022 13:22:07 +0200 Subject: [PATCH] Fix phpstan errors and SolutionProviderRepository types --- src/Config/FileConfigManager.php | 8 +++++++- src/Config/IgnitionConfig.php | 4 +++- src/Contracts/HasSolutionsForThrowable.php | 3 +++ src/Contracts/ProvidesSolution.php | 3 +++ src/Contracts/SolutionProviderRepository.php | 8 ++++---- src/Ignition.php | 3 +-- .../SolutionProviders/SolutionProviderRepository.php | 7 ++++--- .../UndefinedPropertySolutionProvider.php | 2 +- src/Solutions/SolutionTransformer.php | 1 + 9 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Config/FileConfigManager.php b/src/Config/FileConfigManager.php index 79f15fa2..700d3558 100644 --- a/src/Config/FileConfigManager.php +++ b/src/Config/FileConfigManager.php @@ -73,7 +73,8 @@ public function load(): array return $this->readFromFile(); } - protected function readFromFile() + /** @return array */ + protected function readFromFile(): array { if (! $this->isValidFile()) { return []; @@ -120,6 +121,11 @@ protected function createFile(): bool return (file_put_contents($this->file, '') !== false); } + /** + * @param array $options + * + * @return bool + */ protected function saveToFile(array $options): bool { try { diff --git a/src/Config/IgnitionConfig.php b/src/Config/IgnitionConfig.php index fe6b1c4a..e568cabb 100644 --- a/src/Config/IgnitionConfig.php +++ b/src/Config/IgnitionConfig.php @@ -6,6 +6,7 @@ use Spatie\Ignition\Contracts\ConfigManager; use Throwable; +/** @implements Arrayable> */ class IgnitionConfig implements Arrayable { private ConfigManager $manager; @@ -36,6 +37,7 @@ public function setOption(string $name, string $value): self private function initConfigManager(): ConfigManager { try { + /** @phpstan-ignore-next-line */ return app(ConfigManager::class); } catch (Throwable) { return new FileConfigManager(); @@ -121,7 +123,7 @@ public function runnableSolutionsEnabled(): bool return (bool)($this->options['enable_runnable_solutions'] ?? false); } - /** @return array */ + /** @return array> */ public function toArray(): array { return [ diff --git a/src/Contracts/HasSolutionsForThrowable.php b/src/Contracts/HasSolutionsForThrowable.php index 540d3ddc..3b8b1685 100644 --- a/src/Contracts/HasSolutionsForThrowable.php +++ b/src/Contracts/HasSolutionsForThrowable.php @@ -4,6 +4,9 @@ use Throwable; +/** + * Interface used for SolutionProviders. + */ interface HasSolutionsForThrowable { public function canSolve(Throwable $throwable): bool; diff --git a/src/Contracts/ProvidesSolution.php b/src/Contracts/ProvidesSolution.php index 5f8f4561..7d935fef 100644 --- a/src/Contracts/ProvidesSolution.php +++ b/src/Contracts/ProvidesSolution.php @@ -2,6 +2,9 @@ namespace Spatie\Ignition\Contracts; +/** + * Interface to be used on exceptions that provide their own solution. + */ interface ProvidesSolution { public function getSolution(): Solution; diff --git a/src/Contracts/SolutionProviderRepository.php b/src/Contracts/SolutionProviderRepository.php index 1224447b..ce085a7a 100644 --- a/src/Contracts/SolutionProviderRepository.php +++ b/src/Contracts/SolutionProviderRepository.php @@ -7,18 +7,18 @@ interface SolutionProviderRepository { /** - * @param class-string|ProvidesSolution $solutionProviderClass + * @param class-string|HasSolutionsForThrowable $solutionProvider * * @return $this */ - public function registerSolutionProvider(string|ProvidesSolution $solutionProviderClass): self; + public function registerSolutionProvider(string|HasSolutionsForThrowable $solutionProvider): self; /** - * @param array|ProvidesSolution> $solutionProviderClasses + * @param array|HasSolutionsForThrowable> $solutionProviders * * @return $this */ - public function registerSolutionProviders(array $solutionProviderClasses): self; + public function registerSolutionProviders(array $solutionProviders): self; /** * @param Throwable $throwable diff --git a/src/Ignition.php b/src/Ignition.php index e756b83e..c5b660f7 100644 --- a/src/Ignition.php +++ b/src/Ignition.php @@ -14,7 +14,6 @@ use Spatie\FlareClient\Report; use Spatie\Ignition\Config\IgnitionConfig; use Spatie\Ignition\Contracts\HasSolutionsForThrowable; -use Spatie\Ignition\Contracts\ProvidesSolution; use Spatie\Ignition\Contracts\SolutionProviderRepository as SolutionProviderRepositoryContract; use Spatie\Ignition\ErrorPage\ErrorPageViewModel; use Spatie\Ignition\ErrorPage\Renderer; @@ -151,7 +150,7 @@ public function glow( } /** - * @param array> $solutionProviders + * @param array> $solutionProviders * * @return $this */ diff --git a/src/Solutions/SolutionProviders/SolutionProviderRepository.php b/src/Solutions/SolutionProviders/SolutionProviderRepository.php index c7847d22..648e69b9 100644 --- a/src/Solutions/SolutionProviders/SolutionProviderRepository.php +++ b/src/Solutions/SolutionProviders/SolutionProviderRepository.php @@ -20,9 +20,9 @@ public function __construct(array $solutionProviders = []) $this->solutionProviders = Collection::make($solutionProviders); } - public function registerSolutionProvider(string|ProvidesSolution $solutionProviderClass): SolutionProviderRepositoryContract + public function registerSolutionProvider(string|HasSolutionsForThrowable $solutionProvider): SolutionProviderRepositoryContract { - $this->solutionProviders->push($solutionProviderClass); + $this->solutionProviders->push($solutionProvider); return $this; } @@ -85,11 +85,12 @@ public function getSolutionForClass(string $solutionClass): ?Solution return app($solutionClass); } + /** @return Collection */ protected function initialiseSolutionProviderRepositories(): Collection { return $this->solutionProviders ->filter(fn (HasSolutionsForThrowable|string $provider) => in_array(HasSolutionsForThrowable::class, class_implements($provider) ?: [])) - ->map(function (string|HasSolutionsForThrowable $provider) { + ->map(function (string|HasSolutionsForThrowable $provider): HasSolutionsForThrowable { if (is_string($provider)) { return new $provider; } diff --git a/src/Solutions/SolutionProviders/UndefinedPropertySolutionProvider.php b/src/Solutions/SolutionProviders/UndefinedPropertySolutionProvider.php index f2f65bfd..574a6efd 100644 --- a/src/Solutions/SolutionProviders/UndefinedPropertySolutionProvider.php +++ b/src/Solutions/SolutionProviders/UndefinedPropertySolutionProvider.php @@ -110,7 +110,7 @@ protected function findPossibleProperty(string $class, string $invalidPropertyNa /** * @param class-string $class * - * @return Collection + * @return Collection */ protected function getAvailableProperties(string $class): Collection { diff --git a/src/Solutions/SolutionTransformer.php b/src/Solutions/SolutionTransformer.php index 3d775ad3..61c196bf 100644 --- a/src/Solutions/SolutionTransformer.php +++ b/src/Solutions/SolutionTransformer.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Support\Arrayable; use Spatie\Ignition\Contracts\Solution; +/** @implements Arrayable|string|false> */ class SolutionTransformer implements Arrayable { protected Solution $solution;