mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 12:29:43 +01:00
add mask support to isName(), remove matchName()
This commit is contained in:
parent
98bc022c42
commit
f3b296dfcc
@ -70,7 +70,7 @@ CODE_SAMPLE
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->matchName($node, '#^__*#')) {
|
||||
if ($this->isName($node, '__*')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ CODE_SAMPLE
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->matchName($node, '#^(render|action)#')) {
|
||||
if (! $this->isName($node, '#^(render|action)#')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -136,8 +136,11 @@ final class NameResolver
|
||||
public function isName(Node $node, string $name): bool
|
||||
{
|
||||
$resolvedName = $this->resolve($node);
|
||||
if ($resolvedName === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! isset($name[0])) {
|
||||
if ($name === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -146,6 +149,15 @@ final class NameResolver
|
||||
return (bool) Strings::match($resolvedName, $name);
|
||||
}
|
||||
|
||||
// is probably fnmatch
|
||||
if (Strings::contains($name, '*')) {
|
||||
if (fnmatch($name, $resolvedName, FNM_NOESCAPE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $resolvedName === $name;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Rector\Rector;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use Rector\PhpParser\Node\Resolver\NameResolver;
|
||||
|
||||
@ -35,11 +34,6 @@ trait NameResolverTrait
|
||||
return $this->getName($firstNode) === $this->getName($secondNode);
|
||||
}
|
||||
|
||||
public function matchName(Node $node, string $pattern): bool
|
||||
{
|
||||
return (bool) Strings::match($this->getName($node), $pattern);
|
||||
}
|
||||
|
||||
public function isNameInsensitive(Node $node, string $name): bool
|
||||
{
|
||||
return $this->nameResolver->isNameInsensitive($node, $name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user