Skip to content

Commit

Permalink
[CodeQuality] Skip CallableThisArrayToAnonymousFunctionRector when in…
Browse files Browse the repository at this point in the history
…side of Attribute (#2212)

* [CodeQuality] Skip CallableThisArrayToAnonymousFunctionRector when inside of Attribute

* Fixed 🎉
  • Loading branch information
samsonasik authored May 2, 2022
1 parent 1c828ee commit 992d1ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\NodeCollector\NodeAnalyzer;

use PhpParser\Node\Arg;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
Expand Down Expand Up @@ -71,6 +72,11 @@ public function match(Array_ $array): null | ArrayCallableDynamicMethod | ArrayC
return null;
}

$isInAttribute = (bool) $this->betterNodeFinder->findParentType($array, Attribute::class);
if ($isInAttribute) {
return null;
}

$values = $this->valueResolver->getValue($array);
$className = $calleeType->getClassName();
$secondItemValue = $items[1]->value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector\Source\LocaleUtils;

class SkipInAttribute
{
#[Assert\Choice(callback: [LocaleUtils::class, 'getAllLocales'])]
private ?string $locale = null;

public function getLocale(): ?string
{
return $this->locale;
}

public function setLocale(?string $locale): Account
{
$this->locale = $locale;
return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector\Source;

class LocaleUtils
{
public static function getAllLocales(): array
{
return true;
}
}

0 comments on commit 992d1ef

Please sign in to comment.