Skip to content

Commit

Permalink
Fix a number of minor Psalm issues
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Nov 21, 2024
1 parent 7559a0d commit 42134ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
12 changes: 2 additions & 10 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/Command.php">
<MixedAssignment>
<code>$argument</code>
<code><![CDATA[$argument]]></code>
</MixedAssignment>
</file>
<file src="src/ConfigDiscoveryTrait.php">
<DocblockTypeContradiction>
<code><![CDATA[$this->applicationConfigPath]]></code>
</DocblockTypeContradiction>
<MissingReturnType>
<code>removeConfigCacheFile</code>
</MissingReturnType>
<MixedAssignment>
<code><![CDATA[$this->applicationConfig]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code>false|string</code>
<code>null|string</code>
<code>null|string</code>
</MixedInferredReturnType>
<RedundantConditionGivenDocblockType>
<code><![CDATA[isset($this->projectDir)]]></code>
</RedundantConditionGivenDocblockType>
Expand Down
42 changes: 23 additions & 19 deletions src/ConfigDiscoveryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

use RuntimeException;

use function assert;
use function file_exists;
use function is_array;
use function is_string;
use function sprintf;
use function unlink;

use const PHP_EOL;

/**
* Shared functionality for the Disable/Enable commands.
*
* @internal
*/
trait ConfigDiscoveryTrait
{
Expand All @@ -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;
}

Expand All @@ -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 . '.';
}

Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 42134ab

Please sign in to comment.