rector/packages/NodeNameResolver/Regex/RegexPatternDetector.php
Tomas Votruba 9c7734ab41 Updated Rector to commit 363e7910e7360dcee746370de90c3c51eae306a9
363e7910e7 Bump EndBug/add-and-commit from 7.2.1 to 7.4.0 (#943)
2021-10-01 11:43:12 +00:00

28 lines
719 B
PHP

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