| Server IP : 66.29.153.156 / Your IP : 216.73.216.151 Web Server : LiteSpeed System : Linux premium322.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64 User : lastyfjz ( 1521) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /opt/cpanel/ea-wappspector/vendor/rector/rector/src/Validation/ |
Upload File : |
<?php
declare (strict_types=1);
namespace Rector\Validation;
use Rector\Util\StringUtils;
use RectorPrefix202411\Webmozart\Assert\InvalidArgumentException;
/**
* @see \Rector\Tests\Validation\RectorAssertTest
*/
final class RectorAssert
{
/**
* @see https://stackoverflow.com/a/12011255/1348344
* @see https://regex101.com/r/PYQaPF/1
* @var string
*/
private const CLASS_NAME_REGEX = '#^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*$#';
/**
* @see https://stackoverflow.com/a/60470526/1348344
* @see https://regex101.com/r/37aUWA/1
*
* @var string
*/
private const NAKED_NAMESPACE_REGEX = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*[a-zA-Z0-9_\\x7f-\\xff]';
/**
* @see https://www.php.net/manual/en/language.variables.basics.php
* @see https://regex101.com/r/hFw17T/1
*
* @var string
*/
private const PROPERTY_NAME_REGEX = '#^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$#';
/**
* @see https://regex101.com/r/uh5B0S/2
* @see https://www.php.net/manual/en/functions.user-defined.php
* @see https://www.php.net/manual/en/language.constants.php
*
* @var string
*/
private const METHOD_OR_CONSTANT_NAME_REGEX = '#^[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*$#';
/**
* @see https://regex101.com/r/uh5B0S/1
* @see https://www.php.net/manual/en/functions.user-defined.php
*
* @var string
*/
private const FUNCTION_NAME_REGEX = '#^(' . self::NAKED_NAMESPACE_REGEX . '\\\\)?([a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*)$#';
public static function constantName(string $name) : void
{
self::elementName($name, self::METHOD_OR_CONSTANT_NAME_REGEX, 'constant');
}
public static function className(string $name) : void
{
self::elementName($name, self::CLASS_NAME_REGEX, 'class');
}
public static function propertyName(string $name) : void
{
self::elementName($name, self::PROPERTY_NAME_REGEX, 'property');
}
public static function methodName(string $name) : void
{
self::elementName($name, self::METHOD_OR_CONSTANT_NAME_REGEX, 'method');
}
public static function functionName(string $name) : void
{
self::elementName($name, self::FUNCTION_NAME_REGEX, 'function');
}
/**
* @api
*/
public static function elementName(string $name, string $regex, string $elementType) : void
{
if (StringUtils::isMatch($name, $regex)) {
return;
}
$errorMessage = \sprintf('"%s" is not a valid %s name', $name, $elementType);
throw new InvalidArgumentException($errorMessage);
}
}