rector/packages/NodeNameResolver/Regex/RegexPatternDetector.php

28 lines
683 B
PHP
Raw Normal View History

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