Skip to content

Commit

Permalink
Dont replace array keys - not supported in php 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasJancar committed Oct 10, 2024
1 parent 7650d7e commit 9c5fb44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ final class Enumerators {
SomeEnum::USER,
SomeEnum::SUPERUSER,
];

/** @var string[] $indexedArray */
$indexedArray = [
SomeEnum::USER => 'user',
SomeEnum::SUPERUSER => 'superuser',
];
}
}
?>
Expand All @@ -32,12 +26,6 @@ final class Enumerators {
SomeEnum::USER->value,
SomeEnum::SUPERUSER->value,
];

/** @var string[] $indexedArray */
$indexedArray = [
SomeEnum::USER->value => 'user',
SomeEnum::SUPERUSER->value => 'superuser',
];
}
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class UserType extends Enum
/**
* @return string[]
*/
public static function getIndexedArray(): array
public static function getSupportedUserTypes(): array
{
return [
self::USER => 'user',
self::SUPERUSER => 'superuser',
self::USER,
self::SUPERUSER,
];
}
}
Expand Down Expand Up @@ -70,11 +70,11 @@ class UserType extends Enum
/**
* @return string[]
*/
public static function getIndexedArray(): array
public static function getSupportedUserTypes(): array
{
return [
self::USER->value => 'user',
self::SUPERUSER->value => 'superuser',
self::USER->value,
self::SUPERUSER->value,
];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,22 @@ private function refactorArray(Array_ $array): ?Expr
/** @var ArrayItemNode[] $refactoredArrayItems */
$refactoredArrayItems = array_map(fn(
ArrayItem $arrayItem
): ArrayItem => $this->refactorArrayItemKeys($arrayItem), $arrayItems);
): ArrayItem => $this->refactorArrayItem($arrayItem), $arrayItems);

$array->items = $refactoredArrayItems;

return $array;
}


private function refactorArrayItemKeys(ArrayItem $arrayItem): ArrayItem
private function refactorArrayItem(ArrayItem $arrayItem): ArrayItem
{
$key = $arrayItem->key;
$value = $arrayItem->value;

if ($key === null && $value instanceof ClassConstFetch && $this->isMabeEnum($value->class)) {
if ($value instanceof ClassConstFetch && $this->isMabeEnum($value->class)) {
$arrayItem->value = $this->createPropertyValueFetch($value);
}

if ($key instanceof ClassConstFetch && $this->isMabeEnum($key->class)) {
$key = $this->createPropertyValueFetch($key);
$arrayItem->key = $key;
}

return $arrayItem;
}

Expand Down

0 comments on commit 9c5fb44

Please sign in to comment.