2021-02-05 15:15:51 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-02-05 15:15:51 +01:00
|
|
|
namespace Rector\CodeQuality\NodeAnalyzer;
|
|
|
|
|
|
|
|
use PhpParser\Node\Expr\Array_;
|
|
|
|
use PhpParser\Node\Expr\ArrayItem;
|
|
|
|
use PhpParser\Node\Expr\Variable;
|
|
|
|
use PhpParser\Node\Scalar\String_;
|
|
|
|
final class ArrayCompacter
|
|
|
|
{
|
2022-05-27 11:25:02 +00:00
|
|
|
public function compactStringToVariableArray(Array_ $array) : void
|
2021-02-05 15:15:51 +01:00
|
|
|
{
|
|
|
|
foreach ($array->items as $arrayItem) {
|
2022-05-27 11:25:02 +00:00
|
|
|
if (!$arrayItem instanceof ArrayItem) {
|
2021-02-05 15:15:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($arrayItem->key !== null) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-27 11:25:02 +00:00
|
|
|
if (!$arrayItem->value instanceof String_) {
|
2021-02-05 15:15:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$variableName = $arrayItem->value->value;
|
2022-05-27 11:25:02 +00:00
|
|
|
$arrayItem->key = new String_($variableName);
|
|
|
|
$arrayItem->value = new Variable($variableName);
|
2021-02-05 15:15:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|