Skip to content

Commit

Permalink
Fix phpstan errors and SolutionProviderRepository types
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Aug 26, 2022
1 parent 6fde683 commit adf47ca
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/Config/FileConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function load(): array
return $this->readFromFile();
}

protected function readFromFile()
/** @return array<string, mixed> */
protected function readFromFile(): array
{
if (! $this->isValidFile()) {
return [];
Expand Down Expand Up @@ -120,6 +121,11 @@ protected function createFile(): bool
return (file_put_contents($this->file, '') !== false);
}

/**
* @param array<string, mixed> $options
*
* @return bool
*/
protected function saveToFile(array $options): bool
{
try {
Expand Down
4 changes: 3 additions & 1 deletion src/Config/IgnitionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Spatie\Ignition\Contracts\ConfigManager;
use Throwable;

/** @implements Arrayable<string, string|null|bool|array<string, mixed>> */
class IgnitionConfig implements Arrayable
{
private ConfigManager $manager;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -121,7 +123,7 @@ public function runnableSolutionsEnabled(): bool
return (bool)($this->options['enable_runnable_solutions'] ?? false);
}

/** @return array<string, mixed> */
/** @return array<string, string|null|bool|array<string, mixed>> */
public function toArray(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/HasSolutionsForThrowable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Throwable;

/**
* Interface used for SolutionProviders.
*/
interface HasSolutionsForThrowable
{
public function canSolve(Throwable $throwable): bool;
Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/ProvidesSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Contracts/SolutionProviderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
interface SolutionProviderRepository
{
/**
* @param class-string<ProvidesSolution>|ProvidesSolution $solutionProviderClass
* @param class-string<HasSolutionsForThrowable>|HasSolutionsForThrowable $solutionProvider
*
* @return $this
*/
public function registerSolutionProvider(string|ProvidesSolution $solutionProviderClass): self;
public function registerSolutionProvider(string|HasSolutionsForThrowable $solutionProvider): self;

/**
* @param array<class-string<ProvidesSolution>|ProvidesSolution> $solutionProviderClasses
* @param array<class-string<HasSolutionsForThrowable>|HasSolutionsForThrowable> $solutionProviders
*
* @return $this
*/
public function registerSolutionProviders(array $solutionProviderClasses): self;
public function registerSolutionProviders(array $solutionProviders): self;

/**
* @param Throwable $throwable
Expand Down
3 changes: 1 addition & 2 deletions src/Ignition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,7 +150,7 @@ public function glow(
}

/**
* @param array<int, ProvidesSolution|class-string<ProvidesSolution>> $solutionProviders
* @param array<int, HasSolutionsForThrowable|class-string<HasSolutionsForThrowable>> $solutionProviders
*
* @return $this
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -85,11 +85,12 @@ public function getSolutionForClass(string $solutionClass): ?Solution
return app($solutionClass);
}

/** @return Collection<int, HasSolutionsForThrowable> */
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function findPossibleProperty(string $class, string $invalidPropertyNa
/**
* @param class-string $class
*
* @return Collection<string, string>
* @return Collection<int, ReflectionProperty>
*/
protected function getAvailableProperties(string $class): Collection
{
Expand Down
1 change: 1 addition & 0 deletions src/Solutions/SolutionTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Support\Arrayable;
use Spatie\Ignition\Contracts\Solution;

/** @implements Arrayable<string, array<string,string>|string|false> */
class SolutionTransformer implements Arrayable
{
protected Solution $solution;
Expand Down

0 comments on commit adf47ca

Please sign in to comment.