mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
e6e5895517
[Naming] Skip used in arrow function args on RenameVariableToMatchMethodCallReturnTypeRector (#2599)
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\PhpAttribute\AnnotationToAttributeMapper;
|
|
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\Array_;
|
|
use PhpParser\Node\Expr\ArrayItem;
|
|
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
|
|
use Rector\PhpAttribute\AnnotationToAttributeMapper;
|
|
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
|
|
use Rector\PhpAttribute\Enum\DocTagNodeState;
|
|
use RectorPrefix202207\Symfony\Contracts\Service\Attribute\Required;
|
|
use RectorPrefix202207\Webmozart\Assert\Assert;
|
|
/**
|
|
* @implements AnnotationToAttributeMapperInterface<CurlyListNode>
|
|
*/
|
|
final class CurlyListNodeAnnotationToAttributeMapper implements AnnotationToAttributeMapperInterface
|
|
{
|
|
/**
|
|
* @var \Rector\PhpAttribute\AnnotationToAttributeMapper
|
|
*/
|
|
private $annotationToAttributeMapper;
|
|
/**
|
|
* Avoid circular reference
|
|
* @required
|
|
*/
|
|
public function autowire(AnnotationToAttributeMapper $annotationToAttributeMapper) : void
|
|
{
|
|
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
|
|
}
|
|
/**
|
|
* @param mixed $value
|
|
*/
|
|
public function isCandidate($value) : bool
|
|
{
|
|
return $value instanceof CurlyListNode;
|
|
}
|
|
/**
|
|
* @param CurlyListNode $value
|
|
*/
|
|
public function map($value) : \PhpParser\Node\Expr
|
|
{
|
|
$arrayItems = [];
|
|
foreach ($value->getValuesWithExplicitSilentAndWithoutQuotes() as $key => $singleValue) {
|
|
$valueExpr = $this->annotationToAttributeMapper->map($singleValue);
|
|
// remove node
|
|
if ($valueExpr === DocTagNodeState::REMOVE_ARRAY) {
|
|
continue;
|
|
}
|
|
Assert::isInstanceOf($valueExpr, Expr::class);
|
|
$keyExpr = null;
|
|
if (!\is_int($key)) {
|
|
$keyExpr = $this->annotationToAttributeMapper->map($key);
|
|
Assert::isInstanceOf($keyExpr, Expr::class);
|
|
}
|
|
$arrayItems[] = new ArrayItem($valueExpr, $keyExpr);
|
|
}
|
|
return new Array_($arrayItems);
|
|
}
|
|
}
|