add mask support to isName(), remove matchName()

This commit is contained in:
Tomas Votruba 2019-03-15 19:55:57 +01:00
parent 98bc022c42
commit f3b296dfcc
4 changed files with 15 additions and 9 deletions

View File

@ -70,7 +70,7 @@ CODE_SAMPLE
return null;
}
if ($this->matchName($node, '#^__*#')) {
if ($this->isName($node, '__*')) {
return null;
}

View File

@ -332,7 +332,7 @@ CODE_SAMPLE
return true;
}
if (! $this->matchName($node, '#^(render|action)#')) {
if (! $this->isName($node, '#^(render|action)#')) {
return true;
}

View File

@ -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;
}

View File

@ -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);