Skip to content

Commit

Permalink
Merge pull request #427 from ergebnis/fix/constant
Browse files Browse the repository at this point in the history
Fix: Use constants
  • Loading branch information
ergebnis-bot authored Dec 31, 2020
2 parents f80e560 + 2cb22d4 commit 339b91a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
20 changes: 4 additions & 16 deletions src/Vendor/Composer/ConfigHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,13 @@

final class ConfigHashNormalizer implements NormalizerInterface
{
/**
* @phpstan-var list<string>
* @psalm-var list<string>
*
* @var array<int, string>
*/
private static $propertiesThatShouldBeSorted = [
private const PROPERTIES_THAT_SHOULD_BE_SORTED = [
'config',
'extra',
'scripts-descriptions',
];

/**
* @phpstan-var list<string>
* @psalm-var list<string>
*
* @var array<int, string>
*/
private static $propertiesThatShouldNotBeSorted = [
private const PROPERTIES_THAT_SHOULD_NOT_BE_SORTED = [
'preferred-install',
];

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

Expand Down
10 changes: 2 additions & 8 deletions src/Vendor/Composer/PackageHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
* @psalm-var list<string>
*
* @var array<int, string>
*/
private static $propertiesThatShouldBeNormalized = [
private const PROPERTIES_THAT_SHOULD_BE_NORMALIZED = [
'conflict',
'provide',
'replace',
Expand All @@ -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)) {
Expand Down
17 changes: 4 additions & 13 deletions src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,15 @@

final class VersionConstraintNormalizer implements NormalizerInterface
{
/**
* @phpstan-var list<string>
* @psalm-var list<string>
*
* @var array<int, string>
*/
private static $propertiesThatShouldBeNormalized = [
private const PROPERTIES_THAT_SHOULD_BE_NORMALIZED = [
'conflict',
'provide',
'replace',
'require',
'require-dev',
];

/**
* @var array<string, array{0: string, 1: string}>
*/
private static $map = [
private const MAP = [
'and' => [
'{\s*,\s*}',
',',
Expand All @@ -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)) {
Expand Down Expand Up @@ -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<int, string> $split */
$split = \preg_split(
$pattern,
Expand Down

0 comments on commit 339b91a

Please sign in to comment.