From 2cb22d4bb3af8abe8017659ada619c3e016196b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 31 Dec 2020 10:13:30 +0100 Subject: [PATCH] Fix: Use constants --- src/Vendor/Composer/ConfigHashNormalizer.php | 20 ++++--------------- src/Vendor/Composer/PackageHashNormalizer.php | 10 ++-------- .../Composer/VersionConstraintNormalizer.php | 17 ++++------------ 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/Vendor/Composer/ConfigHashNormalizer.php b/src/Vendor/Composer/ConfigHashNormalizer.php index 5ffa7ed3..6d0a26c4 100644 --- a/src/Vendor/Composer/ConfigHashNormalizer.php +++ b/src/Vendor/Composer/ConfigHashNormalizer.php @@ -18,25 +18,13 @@ final class ConfigHashNormalizer implements NormalizerInterface { - /** - * @phpstan-var list - * @psalm-var list - * - * @var array - */ - private static $propertiesThatShouldBeSorted = [ + private const PROPERTIES_THAT_SHOULD_BE_SORTED = [ 'config', 'extra', 'scripts-descriptions', ]; - /** - * @phpstan-var list - * @psalm-var list - * - * @var array - */ - private static $propertiesThatShouldNotBeSorted = [ + private const PROPERTIES_THAT_SHOULD_NOT_BE_SORTED = [ 'preferred-install', ]; @@ -50,7 +38,7 @@ public function normalize(Json $json): Json $objectPropertiesThatShouldBeNormalized = \array_intersect_key( \get_object_vars($decoded), - \array_flip(self::$propertiesThatShouldBeSorted) + \array_flip(self::PROPERTIES_THAT_SHOULD_BE_SORTED) ); if (0 === \count($objectPropertiesThatShouldBeNormalized)) { @@ -77,7 +65,7 @@ public function normalize(Json $json): Json */ private static function sortByKey(string $name, $value) { - if (\in_array($name, self::$propertiesThatShouldNotBeSorted, true)) { + if (\in_array($name, self::PROPERTIES_THAT_SHOULD_NOT_BE_SORTED, true)) { return $value; } diff --git a/src/Vendor/Composer/PackageHashNormalizer.php b/src/Vendor/Composer/PackageHashNormalizer.php index 02e50443..cc0c7fa4 100644 --- a/src/Vendor/Composer/PackageHashNormalizer.php +++ b/src/Vendor/Composer/PackageHashNormalizer.php @@ -23,13 +23,7 @@ final class PackageHashNormalizer implements NormalizerInterface */ private const PLATFORM_PACKAGE_REGEX = '{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[^/ ]+)$}i'; - /** - * @phpstan-var list - * @psalm-var list - * - * @var array - */ - private static $propertiesThatShouldBeNormalized = [ + private const PROPERTIES_THAT_SHOULD_BE_NORMALIZED = [ 'conflict', 'provide', 'replace', @@ -48,7 +42,7 @@ public function normalize(Json $json): Json $objectPropertiesThatShouldBeNormalized = \array_intersect_key( \get_object_vars($decoded), - \array_flip(self::$propertiesThatShouldBeNormalized) + \array_flip(self::PROPERTIES_THAT_SHOULD_BE_NORMALIZED) ); if (0 === \count($objectPropertiesThatShouldBeNormalized)) { diff --git a/src/Vendor/Composer/VersionConstraintNormalizer.php b/src/Vendor/Composer/VersionConstraintNormalizer.php index 6c44de1c..99914bb5 100644 --- a/src/Vendor/Composer/VersionConstraintNormalizer.php +++ b/src/Vendor/Composer/VersionConstraintNormalizer.php @@ -18,13 +18,7 @@ final class VersionConstraintNormalizer implements NormalizerInterface { - /** - * @phpstan-var list - * @psalm-var list - * - * @var array - */ - private static $propertiesThatShouldBeNormalized = [ + private const PROPERTIES_THAT_SHOULD_BE_NORMALIZED = [ 'conflict', 'provide', 'replace', @@ -32,10 +26,7 @@ final class VersionConstraintNormalizer implements NormalizerInterface 'require-dev', ]; - /** - * @var array - */ - private static $map = [ + private const MAP = [ 'and' => [ '{\s*,\s*}', ',', @@ -60,7 +51,7 @@ public function normalize(Json $json): Json $objectPropertiesThatShouldBeNormalized = \array_intersect_key( \get_object_vars($decoded), - \array_flip(self::$propertiesThatShouldBeNormalized) + \array_flip(self::PROPERTIES_THAT_SHOULD_BE_NORMALIZED) ); if (0 === \count($objectPropertiesThatShouldBeNormalized)) { @@ -89,7 +80,7 @@ private static function normalizeVersionConstraint(string $versionConstraint): s { $normalized = $versionConstraint; - foreach (self::$map as [$pattern, $glue]) { + foreach (self::MAP as [$pattern, $glue]) { /** @var array $split */ $split = \preg_split( $pattern,