From d49bd701c8c6be71ff354b9caf13c9822783baf5 Mon Sep 17 00:00:00 2001 From: Enea Date: Fri, 26 Jul 2024 19:31:16 +0200 Subject: [PATCH] cs:fix --- src/AurynConfig.php | 8 ++++++++ src/ProvidersCache.php | 18 +++++++++++++----- src/ProvidersCollection.php | 7 +++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/AurynConfig.php b/src/AurynConfig.php index b38a83a..be6f87e 100644 --- a/src/AurynConfig.php +++ b/src/AurynConfig.php @@ -43,6 +43,10 @@ class AurynConfig implements AurynConfigInterface private array $extensions = []; private ProxyFactoryInterface $proxy_factory; + + /** + * @var array + */ private array $extensionsClasses = []; /** @@ -73,6 +77,7 @@ public function resolve(): void } foreach ($this->extensionsClasses as $extensionClass) { + /** @var Extension $extension */ $extension = $this->injector->share($extensionClass)->make($extensionClass); $extension->execute($this); } @@ -82,6 +87,9 @@ public function resolve(): void } } + /** + * @param class-string $className + */ public function extendFromClassName(string $className): void { $this->extensionsClasses[] = $className; diff --git a/src/ProvidersCache.php b/src/ProvidersCache.php index cc44034..d2153ce 100644 --- a/src/ProvidersCache.php +++ b/src/ProvidersCache.php @@ -7,10 +7,14 @@ use Brick\VarExporter\ExportException; use Brick\VarExporter\VarExporter; use ItalyStrap\Config\ConfigInterface; +use phpDocumentor\Reflection\Types\Self_; use Safe\DateTimeImmutable; use Webimpress\SafeWriter\Exception\ExceptionInterface as FileWriterException; use Webimpress\SafeWriter\FileWriter; +/** + * @psalm-api + */ class ProvidersCache implements ProvidersCacheInterface { private const CACHE_TEMPLATE = <<<'EOT' @@ -35,15 +39,19 @@ public function read( ConfigInterface $config ): bool { - $cachedConfigFile = (string)$config->get(static::CACHE_PATH, $this->file); + $cachedConfigFile = (string)$config->get(self::CACHE_PATH, $this->file); if ( - !$cachedConfigFile + $cachedConfigFile === '' || !file_exists($cachedConfigFile) + || !is_readable($cachedConfigFile) ) { return false; } + /** + * @psalm-suppress UnresolvableInclude + */ $config->merge((array)require $cachedConfigFile); return true; } @@ -51,15 +59,15 @@ public function read( public function write( ConfigInterface $config ): void { - $cachedConfigFile = (string)$config->get(static::CACHE_PATH, $this->file); + $cachedConfigFile = (string)$config->get(self::CACHE_PATH, $this->file); - if (!$cachedConfigFile) { + if ($cachedConfigFile === '') { return; } try { $contents = sprintf( - static::CACHE_TEMPLATE, + self::CACHE_TEMPLATE, static::class, // Write an alternative to date('c') (new DateTimeImmutable('now'))->format('c'), diff --git a/src/ProvidersCollection.php b/src/ProvidersCollection.php index 6d2a69c..e854c52 100644 --- a/src/ProvidersCollection.php +++ b/src/ProvidersCollection.php @@ -18,7 +18,7 @@ class ProvidersCollection { private ConfigInterface $config; private Injector $injector; - private ProvidersCacheInterface $cache; + private ProvidersCache $cache; /** * @var array|callable[]|iterable|string[] */ @@ -28,14 +28,13 @@ class ProvidersCollection * @param Injector $injector * @param ConfigInterface $config * @param iterable $providers - * @param ProvidersCacheInterface|null $cache - * @throws \ErrorException + * @param ProvidersCache|null $cache */ public function __construct( Injector $injector, ConfigInterface $config, iterable $providers = [], - ProvidersCacheInterface $cache = null + ProvidersCache $cache = null ) { $this->injector = $injector; $this->config = $config;