diff --git a/CHANGELOG.md b/CHANGELOG.md index 08276e8..0642e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/ncc/CLI/Management/PackageManagerMenu.php b/src/ncc/CLI/Management/PackageManagerMenu.php index a3bd820..dbc9d32 100644 --- a/src/ncc/CLI/Management/PackageManagerMenu.php +++ b/src/ncc/CLI/Management/PackageManagerMenu.php @@ -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); diff --git a/src/ncc/Enums/RegexPatterns.php b/src/ncc/Enums/RegexPatterns.php index 51fc1f3..d57a677 100644 --- a/src/ncc/Enums/RegexPatterns.php +++ b/src/ncc/Enums/RegexPatterns.php @@ -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 = '/^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?: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[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m'; + case SEMANTIC_VERSIONING_2 = '/^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?: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[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 */ - public const REMOTE_PACKAGE = '/^(?[^\/\n]+)\/(?[^:=\n@]+)(?:=(?[^:@\n]+))?(?::(?[^@\n]+))?@(?.*)$/m'; + case REMOTE_PACKAGE = '/^(?[^\/\n]+)\/(?[^:=\n@]+)(?:=(?[^:@\n]+))?(?::(?[^@\n]+))?@(?.*)$/m'; } \ No newline at end of file diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index 9ba157b..f499bcd 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -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); } diff --git a/src/ncc/Objects/ProjectConfiguration/Assembly.php b/src/ncc/Objects/ProjectConfiguration/Assembly.php index 4c44801..684f87e 100644 --- a/src/ncc/Objects/ProjectConfiguration/Assembly.php +++ b/src/ncc/Objects/ProjectConfiguration/Assembly.php @@ -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)); } diff --git a/src/ncc/Objects/RemotePackageInput.php b/src/ncc/Objects/RemotePackageInput.php index 880ae86..eaa416d 100644 --- a/src/ncc/Objects/RemotePackageInput.php +++ b/src/ncc/Objects/RemotePackageInput.php @@ -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) { diff --git a/src/ncc/Utilities/Validate.php b/src/ncc/Utilities/Validate.php index b661aae..df31364 100644 --- a/src/ncc/Utilities/Validate.php +++ b/src/ncc/Utilities/Validate.php @@ -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; }