diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b40544e..29963b4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,25 +1,17 @@ - + - $argument + applicationConfigPath]]> - - removeConfigCacheFile - applicationConfig]]> - - false|string - null|string - null|string - projectDir)]]> diff --git a/src/ConfigDiscoveryTrait.php b/src/ConfigDiscoveryTrait.php index e96b4f2..42328ab 100644 --- a/src/ConfigDiscoveryTrait.php +++ b/src/ConfigDiscoveryTrait.php @@ -6,8 +6,10 @@ use RuntimeException; +use function assert; use function file_exists; use function is_array; +use function is_string; use function sprintf; use function unlink; @@ -15,6 +17,8 @@ /** * Shared functionality for the Disable/Enable commands. + * + * @internal */ trait ConfigDiscoveryTrait { @@ -33,11 +37,11 @@ trait ConfigDiscoveryTrait /** * Removes the application configuration cache file, if present. */ - private function removeConfigCacheFile() + private function removeConfigCacheFile(): void { $configCacheFile = $this->getConfigCacheFile(); - if (! $configCacheFile || ! file_exists($configCacheFile)) { + if ($configCacheFile === false || ! file_exists($configCacheFile)) { return; } @@ -51,20 +55,20 @@ private function getConfigCacheFile(): false|string { $config = $this->getApplicationConfig(); - if (isset($config['config_cache_path'])) { + if (isset($config['config_cache_path']) && is_string($config['config_cache_path'])) { return $config['config_cache_path']; } $configCacheDir = $this->getConfigCacheDir(); - if (! $configCacheDir) { + if ($configCacheDir === null) { return false; } $path = sprintf('%s/%s.', $configCacheDir, $this->configCacheBase); $configCacheKey = $this->getConfigCacheKey(); - if ($configCacheKey) { + if ($configCacheKey !== null) { $path .= $configCacheKey . '.'; } @@ -73,32 +77,32 @@ private function getConfigCacheFile(): false|string /** * Return the configured configuration cache directory, if any. - * - * @return null|string */ - private function getConfigCacheDir() + private function getConfigCacheDir(): string|null { - $config = $this->getApplicationConfig(); - if (empty($config['module_listener_options']['cache_dir'])) { - return null; - } + $config = $this->getApplicationConfig(); + $options = $config['module_listener_options'] ?? []; + assert(is_array($options)); + /** @psalm-var mixed $directory */ + $directory = $options['cache_dir'] ?? null; - return $config['module_listener_options']['cache_dir']; + return is_string($directory) && $directory !== '' ? $directory : null; } /** * Return the configured configuration cache key, if any. - * - * @return null|string */ - private function getConfigCacheKey() + private function getConfigCacheKey(): null|string { - $config = $this->getApplicationConfig(); - if (empty($config['module_listener_options']['config_cache_key'])) { + $config = $this->getApplicationConfig(); + $options = $config['module_listener_options'] ?? []; + assert(is_array($options)); + $key = $options['config_cache_key'] ?? null; + if (! is_string($key) || $key === '') { return null; } - return $config['module_listener_options']['config_cache_key']; + return $key; } /**