Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeQuality] Skip CallableThisArrayToAnonymousFunctionRector when inside of Attribute #2212

Merged
merged 2 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}