From c88c6dbc384b0a326823ba897bf75bbe3e8a206f Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 20 Jan 2024 13:01:34 -0300 Subject: [PATCH] Psalm 2. --- psalm.xml | 2 +- src/Converter/SemverUtil.php | 8 ++--- src/Foxy.php | 42 ++++++------------------- src/Json/JsonFile.php | 4 +-- src/Json/JsonFormatter.php | 4 +-- tests/Converter/SemverConverterTest.php | 9 ++++++ 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/psalm.xml b/psalm.xml index 047bdfc..09a00cf 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ 0) { [$type, $version, $end] = self::cleanVersion(strtolower($version), $matches); [$version, $patchVersion] = self::matchVersion($version, $type); @@ -73,6 +69,8 @@ public static function convertVersionMetadata(string $version): string * @param string $pattern The pattern without '/'. * * @return string The full pattern with '/'. + * + * @psalm-return non-empty-string */ public static function createPattern(string $pattern): string { diff --git a/src/Foxy.php b/src/Foxy.php index 6bfe9aa..d085f34 100644 --- a/src/Foxy.php +++ b/src/Foxy.php @@ -40,40 +40,18 @@ * Composer plugin. * * @author François Pluchino + * + * @psalm-suppress MissingConstructor */ final class Foxy implements PluginInterface, EventSubscriberInterface { - public const REQUIRED_COMPOSER_VERSION = '^2.0.0'; - - /** - * @var Config - */ - protected $config; - - /** - * @var AssetManagerInterface - */ - protected $assetManager; - - /** - * @var AssetFallback - */ - protected $assetFallback; - - /** - * @var ComposerFallback - */ - protected $composerFallback; - - /** - * @var SolverInterface - */ - protected $solver; - - /** - * @var bool - */ - protected $initialized = false; + final public const REQUIRED_COMPOSER_VERSION = '^2.0.0'; + private Config $config; + private AssetManagerInterface $assetManager; + private AssetFallback $assetFallback; + private ComposerFallback $composerFallback; + private SolverInterface $solver; + private bool $initialized = false; /** * The list of the classes of asset managers. @@ -89,7 +67,7 @@ final class Foxy implements PluginInterface, EventSubscriberInterface /** * The default values of config. */ - private static $defaultConfig = [ + private static array $defaultConfig = [ 'enabled' => true, 'manager' => null, 'manager-version' => [ diff --git a/src/Json/JsonFile.php b/src/Json/JsonFile.php index a6b655a..fbdc6e2 100644 --- a/src/Json/JsonFile.php +++ b/src/Json/JsonFile.php @@ -21,7 +21,7 @@ final class JsonFile extends \Composer\Json\JsonFile { /** - * @psalm-var string[]|null + * @psalm-var string[] */ private array $arrayKeys = []; private int|null $indent = null; @@ -42,7 +42,7 @@ public function getArrayKeys(): array $this->parseOriginalContent(); } - return $this->arrayKeys ?? []; + return $this->arrayKeys; } /** diff --git a/src/Json/JsonFormatter.php b/src/Json/JsonFormatter.php index 84f5226..6131ef4 100644 --- a/src/Json/JsonFormatter.php +++ b/src/Json/JsonFormatter.php @@ -91,7 +91,7 @@ private static function formatInternal(string $json, bool $unescapeUnicode, bool $array = \json_decode($json, true); if ($unescapeUnicode) { - \array_walk_recursive($array, function (&$item): void { + \array_walk_recursive($array, function (mixed &$item): void { if (\is_string($item)) { $item = \preg_replace_callback( '/\\\\u([0-9a-fA-F]{4})/', @@ -106,7 +106,7 @@ static function (mixed $match) { } if ($unescapeSlashes) { - \array_walk_recursive($array, function (&$item): void { + \array_walk_recursive($array, function (mixed &$item): void { if (\is_string($item)) { $item = \str_replace('\\/', '/', $item); } diff --git a/tests/Converter/SemverConverterTest.php b/tests/Converter/SemverConverterTest.php index 196b879..0501b6c 100644 --- a/tests/Converter/SemverConverterTest.php +++ b/tests/Converter/SemverConverterTest.php @@ -14,6 +14,7 @@ namespace Foxy\Tests\Converter; use Foxy\Converter\SemverConverter; +use Foxy\Converter\SemverUtil; use Foxy\Converter\VersionConverterInterface; use PHPUnit\Framework\TestCase; @@ -100,4 +101,12 @@ public static function getTestVersions(): array ['', '*'], ]; } + + public function testConvertVersionMetadataWithEmptyPattern() + { + $version = '1.0.0'; + $expected = '1.0.0'; + + static::assertSame($expected, SemverUtil::convertVersionMetadata($version)); + } }