Convert RegexPatterns constants to enum cases
This commit is contained in:
parent
7e5cdf4d64
commit
e98b949b7d
7 changed files with 24 additions and 23 deletions
|
@ -13,6 +13,7 @@ This update introduces a refactored code-base, code quality improvements, and be
|
|||
- Convert Versions constants to enum cases
|
||||
- Update Scopes to enum and adjust scope checks
|
||||
- Convert Runners class to enum with string cases
|
||||
- Convert RegexPatterns constants to enum cases
|
||||
|
||||
### Removed
|
||||
- Removed EncoderType enum file, unused.
|
||||
|
|
|
@ -199,7 +199,7 @@
|
|||
$authentication_entry = $entry->getPassword();
|
||||
}
|
||||
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE, $package) === 1)
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE->value, $package) === 1)
|
||||
{
|
||||
$package_input = RemotePackageInput::fromString($package);
|
||||
|
||||
|
|
|
@ -26,27 +26,27 @@
|
|||
* @author Zi Xing Narrakas
|
||||
* @copyright Copyright (C) 2022-2023. Nosial - All Rights Reserved.
|
||||
*/
|
||||
final class RegexPatterns
|
||||
enum RegexPatterns : string
|
||||
{
|
||||
public const UUID = '{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di';
|
||||
case UUID = '{^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$}Di';
|
||||
|
||||
public const PACKAGE_NAME_FORMAT = '/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/';
|
||||
case PACKAGE_NAME_FORMAT = '/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/';
|
||||
|
||||
public const COMPOSER_VERSION_FORMAT = '/^([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
|
||||
case COMPOSER_VERSION_FORMAT = '/^([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
|
||||
|
||||
public const PYTHON_VERSION_FORMAT = '/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
|
||||
case PYTHON_VERSION_FORMAT = '/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
|
||||
|
||||
public const SEMANTIC_VERSIONING_2 = '/^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m';
|
||||
case SEMANTIC_VERSIONING_2 = '/^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m';
|
||||
|
||||
public const UNIX_PATH = '/^(((?:\.\/|\.\.\/|\/)?(?:\.?\w+\/)*)(\.?\w+\.?\w+))$/m';
|
||||
case UNIX_PATH = '/^(((?:\.\/|\.\.\/|\/)?(?:\.?\w+\/)*)(\.?\w+\.?\w+))$/m';
|
||||
|
||||
public const CONSTANT_NAME = '/^([^\x00-\x7F]|[\w_\ \.\+\-]){2,64}$/';
|
||||
case CONSTANT_NAME = '/^([^\x00-\x7F]|[\w_\ \.\+\-]){2,64}$/';
|
||||
|
||||
public const EXECUTION_POLICY_NAME = '/^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/m';
|
||||
case EXECUTION_POLICY_NAME = '/^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/m';
|
||||
|
||||
/**
|
||||
* @author <purplex>
|
||||
*/
|
||||
public const REMOTE_PACKAGE = '/^(?<vendor>[^\/\n]+)\/(?<package>[^:=\n@]+)(?:=(?<version>[^:@\n]+))?(?::(?<branch>[^@\n]+))?@(?<source>.*)$/m';
|
||||
case REMOTE_PACKAGE = '/^(?<vendor>[^\/\n]+)\/(?<package>[^:=\n@]+)(?:=(?<version>[^:@\n]+))?(?::(?<branch>[^@\n]+))?@(?<source>.*)$/m';
|
||||
|
||||
}
|
|
@ -169,7 +169,7 @@
|
|||
}
|
||||
|
||||
// If the input is a remote package, we can assume it's a remote package input
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE, $input) === 1)
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE->value, $input) === 1)
|
||||
{
|
||||
return $this->installRemotePackage(RemotePackageInput::fromString($input), $authentication, $options);
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@
|
|||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
if(!preg_match(RegexPatterns::UUID, $this->uuid))
|
||||
if(!preg_match(RegexPatterns::UUID->value, $this->uuid))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('The UUID is not a valid v4 UUID: %s, in property assembly.uuid', $this->uuid));
|
||||
}
|
||||
|
@ -277,7 +277,7 @@
|
|||
throw new ConfigurationException(sprintf('The version number is invalid: %s, in property assembly.version', $this->version));
|
||||
}
|
||||
|
||||
if($this->package !== null && !preg_match(RegexPatterns::PACKAGE_NAME_FORMAT, $this->package))
|
||||
if($this->package !== null && !preg_match(RegexPatterns::PACKAGE_NAME_FORMAT->value, $this->package))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('The package name is invalid: %s, in property assembly.package', $this->package));
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@
|
|||
*/
|
||||
public static function fromString(string $input): RemotePackageInput
|
||||
{
|
||||
if (preg_match(RegexPatterns::REMOTE_PACKAGE, $input, $matches))
|
||||
if (preg_match(RegexPatterns::REMOTE_PACKAGE->value, $input, $matches))
|
||||
{
|
||||
if ($matches['package'] === null || $matches['vendor'] === null)
|
||||
{
|
||||
|
|
|
@ -76,17 +76,17 @@ namespace ncc\Utilities;
|
|||
*/
|
||||
public static function version(string $input): bool
|
||||
{
|
||||
if(preg_match(RegexPatterns::SEMANTIC_VERSIONING_2, $input))
|
||||
if(preg_match(RegexPatterns::SEMANTIC_VERSIONING_2->value, $input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(preg_match(RegexPatterns::COMPOSER_VERSION_FORMAT, $input))
|
||||
if(preg_match(RegexPatterns::COMPOSER_VERSION_FORMAT->value, $input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(preg_match(RegexPatterns::PYTHON_VERSION_FORMAT, $input))
|
||||
if(preg_match(RegexPatterns::PYTHON_VERSION_FORMAT->value, $input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ namespace ncc\Utilities;
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!preg_match(RegexPatterns::PACKAGE_NAME_FORMAT, $input))
|
||||
if(!preg_match(RegexPatterns::PACKAGE_NAME_FORMAT->value, $input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ namespace ncc\Utilities;
|
|||
*/
|
||||
public static function unixFilepath($input): bool
|
||||
{
|
||||
if(preg_match(RegexPatterns::UNIX_PATH, $input))
|
||||
if(preg_match(RegexPatterns::UNIX_PATH->value, $input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ namespace ncc\Utilities;
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!preg_match(RegexPatterns::CONSTANT_NAME, $input))
|
||||
if(!preg_match(RegexPatterns::CONSTANT_NAME->value, $input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ namespace ncc\Utilities;
|
|||
*/
|
||||
public static function executionPolicyName(string $input): bool
|
||||
{
|
||||
if(!preg_match(RegexPatterns::EXECUTION_POLICY_NAME, $input))
|
||||
if(!preg_match(RegexPatterns::EXECUTION_POLICY_NAME->value, $input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ namespace ncc\Utilities;
|
|||
*/
|
||||
public static function remotePackageInput(string $input): bool
|
||||
{
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE, $input))
|
||||
if(preg_match(RegexPatterns::REMOTE_PACKAGE->value, $input))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue