2020-02-13 11:09:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Rector\NodeNameResolver\Regex;
|
|
|
|
|
|
|
|
use Nette\Utils\Strings;
|
|
|
|
|
|
|
|
final class RegexPatternDetector
|
|
|
|
{
|
2020-02-17 16:13:38 +01:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*
|
|
|
|
* This prevents miss matching like "aMethoda"
|
|
|
|
*/
|
|
|
|
private const POSSIBLE_DELIMITERS = ['#', '~', '/'];
|
|
|
|
|
2020-02-13 11:09:51 +01:00
|
|
|
public function isRegexPattern(string $name): bool
|
|
|
|
{
|
|
|
|
if (Strings::length($name) <= 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$firstChar = $name[0];
|
|
|
|
$lastChar = $name[strlen($name) - 1];
|
|
|
|
if ($firstChar !== $lastChar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-17 16:13:38 +01:00
|
|
|
return in_array($firstChar, self::POSSIBLE_DELIMITERS, true);
|
2020-02-13 11:09:51 +01:00
|
|
|
}
|
|
|
|
}
|