Skip to content

Commit

Permalink
Fix psalm and phpstan errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 3, 2024
1 parent f413a86 commit 8f59682
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
27 changes: 27 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
<code>setInput</code>
</PossiblyNullReference>
</file>
<file src="src/Config/Config.php">
<DeprecatedMethod>
<code>getEnvironments</code>
<code>getEnvironments</code>
<code>hasEnvironment</code>
<code>hasEnvironment</code>
<code>searchNamespace</code>
<code>searchNamespace</code>
</DeprecatedMethod>
<LessSpecificImplementedReturnType>
<code>array</code>
<code>array</code>
<code>array</code>
<code>array</code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Config/ConfigInterface.php">
<MissingTemplateParam>
<code>ArrayAccess</code>
</MissingTemplateParam>
</file>
<file src="src/Db/Adapter/AbstractAdapter.php">
<RedundantPropertyInitializationCheck>
<code><![CDATA[isset($this->output)]]></code>
Expand Down Expand Up @@ -82,6 +103,12 @@
<ArgumentTypeCoercion>
<code>array_merge($versions, array_keys($migrations))</code>
</ArgumentTypeCoercion>
<DeprecatedMethod>
<code>getDataDomain</code>
<code>getMigrationNamespaceByPath</code>
<code>getSeedNamespaceByPath</code>
<code>hasEnvironment</code>
</DeprecatedMethod>
<RedundantPropertyInitializationCheck>
<code><![CDATA[isset($this->container)]]></code>
</RedundantPropertyInitializationCheck>
Expand Down
23 changes: 10 additions & 13 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public function __construct(array $configArray, ?string $configFilePath = null)
{
$this->configFilePath = $configFilePath;
$this->values = $this->replaceTokens($configArray);

if (isset($this->values['feature_flags'])) {
FeatureFlags::setFlagsFromConfig($this->values['feature_flags']);
}
}

/**
Expand Down Expand Up @@ -87,7 +83,7 @@ public static function fromYaml(string $configFilePath): ConfigInterface
));

Check warning on line 83 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L79-L83

Added lines #L79 - L83 were not covered by tests
}

return new static($configArray, $configFilePath);
return new Config($configArray, $configFilePath);

Check warning on line 86 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L86

Added line #L86 was not covered by tests
}

/**
Expand All @@ -114,7 +110,7 @@ public static function fromJson(string $configFilePath): ConfigInterface
));

Check warning on line 110 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L105-L110

Added lines #L105 - L110 were not covered by tests
}

return new static($configArray, $configFilePath);
return new Config($configArray, $configFilePath);

Check warning on line 113 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L113

Added line #L113 was not covered by tests
}

/**
Expand All @@ -141,7 +137,7 @@ public static function fromPhp(string $configFilePath): ConfigInterface
));

Check warning on line 137 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L133-L137

Added lines #L133 - L137 were not covered by tests
}

return new static($configArray, $configFilePath);
return new Config($configArray, $configFilePath);

Check warning on line 140 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L140

Added line #L140 was not covered by tests
}

/**
Expand Down Expand Up @@ -323,7 +319,7 @@ public function getSeedBaseClassName(bool $dropNamespace = true): string
{
$className = !isset($this->values['seed_base_class']) ? 'Phinx\Seed\AbstractSeed' : $this->values['seed_base_class'];

Check warning on line 320 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L320

Added line #L320 was not covered by tests

return $dropNamespace ? substr(strrchr($className, '\\'), 1) : $className;
return $dropNamespace ? substr((string)strrchr($className, '\\'), 1) : $className;

Check warning on line 322 in src/Config/Config.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Config.php#L322

Added line #L322 was not covered by tests
}

/**
Expand Down Expand Up @@ -425,8 +421,8 @@ public function getBootstrapFile(): string|false
/**
* Replace tokens in the specified array.
*
* @param array $arr Array to replace
* @return array
* @param array<string, mixed> $arr Array to replace
* @return array<string, mixed>
*/
protected function replaceTokens(array $arr): array
{
Expand All @@ -435,7 +431,7 @@ protected function replaceTokens(array $arr): array
// environment variables either end up in $_SERVER (most likely) or $_ENV,
// so we search through both

/** @var array<string, string> $tokens */
/** @var array<string, string|null> $tokens */
$tokens = [];
foreach (array_merge($_ENV, $_SERVER) as $varname => $varvalue) {
if (strpos($varname, 'PHINX_') === 0) {
Expand All @@ -455,11 +451,12 @@ protected function replaceTokens(array $arr): array
* Recurse an array for the specified tokens and replace them.
*
* @param array $arr Array to recurse
* @param string|null[] $tokens Array of tokens to search for
* @return array
* @param array<string, string|null> $tokens Array of tokens to search for
* @return array<string, mixed>
*/
protected function recurseArrayForTokens(array $arr, array $tokens): array
{
/** @var array<string, mixed> $out */
$out = [];
foreach ($arr as $name => $value) {
if (is_array($value)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

/**
* Phinx configuration interface.
*
* @template-implemements ArrayAccess<string>
*/
interface ConfigInterface extends ArrayAccess
{
Expand Down

0 comments on commit 8f59682

Please sign in to comment.