diff --git a/src/ncc/Abstracts/ExceptionCodes.php b/src/ncc/Abstracts/ExceptionCodes.php index c079675..3e904b9 100644 --- a/src/ncc/Abstracts/ExceptionCodes.php +++ b/src/ncc/Abstracts/ExceptionCodes.php @@ -16,12 +16,15 @@ use ncc\Exceptions\InvalidProjectBuildConfiguration; use ncc\Exceptions\InvalidProjectConfigurationException; use ncc\Exceptions\InvalidProjectNameException; + use ncc\Exceptions\InvalidPropertyValueException; use ncc\Exceptions\InvalidScopeException; + use ncc\Exceptions\InvalidVersionConfigurationException; use ncc\Exceptions\InvalidVersionNumberException; use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\NoUnitsFoundException; use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Exceptions\RuntimeException; + use ncc\Exceptions\UnsupportedCompilerExtensionException; use ncc\Exceptions\UnsupportedPackageException; /** @@ -145,6 +148,26 @@ */ const InvalidProjectBuildConfiguration = -1722; + /** + * @see UnsupportedCompilerExtensionException + */ + const UnsupportedCompilerExtensionException = -1723; + + /** + * @see InvalidPropertyValueException + */ + const InvalidPropertyValueException = -1724; + + /** + * @see InvalidVersionConfigurationException + */ + const InvalidVersionConfigurationException = -1725; + + /** + * @see UnsupportedExtensionVersionException + */ + const UnsupportedExtensionVersionException = -1726; + /** * All the exception codes from NCC */ @@ -171,6 +194,10 @@ self::InvalidConstantNameException, self::PackagePreparationFailedException, self::BuildConfigurationNotFoundException, - self::InvalidProjectBuildConfiguration + self::InvalidProjectBuildConfiguration, + self::UnsupportedCompilerExtensionException, + self::InvalidPropertyValueException, + self::InvalidVersionConfigurationException, + self::UnsupportedExtensionVersionException ]; } \ No newline at end of file diff --git a/src/ncc/Exceptions/InvalidPropertyValueException.php b/src/ncc/Exceptions/InvalidPropertyValueException.php new file mode 100644 index 0000000..eb1ac64 --- /dev/null +++ b/src/ncc/Exceptions/InvalidPropertyValueException.php @@ -0,0 +1,11 @@ +message = $message; + $this->previous = $previous; + } + } \ No newline at end of file diff --git a/src/ncc/Exceptions/UnsupportedCompilerExtensionException.php b/src/ncc/Exceptions/UnsupportedCompilerExtensionException.php new file mode 100644 index 0000000..ddd520c --- /dev/null +++ b/src/ncc/Exceptions/UnsupportedCompilerExtensionException.php @@ -0,0 +1,28 @@ +message = $message; + $this->previous = $previous; + } + } \ No newline at end of file diff --git a/src/ncc/Exceptions/UnsupportedExtensionVersionException.php b/src/ncc/Exceptions/UnsupportedExtensionVersionException.php new file mode 100644 index 0000000..f24b429 --- /dev/null +++ b/src/ncc/Exceptions/UnsupportedExtensionVersionException.php @@ -0,0 +1,13 @@ +Extension == null) + { + if($throw_exception) + throw new InvalidPropertyValueException('The property \'extension\' must not be null.'); + return False; + } + + if($this->MinimumVersion == null) + { + if($throw_exception) + throw new InvalidPropertyValueException('The property \'minimum_version\' must not be null.'); + + return False; + } + + if($this->MaximumVersion == null) + { + if($throw_exception) + throw new InvalidPropertyValueException('The property \'maximum_version\' must not be null.'); + return False; + } + + try + { + if(VersionComparator::compareVersion($this->MinimumVersion, $this->MaximumVersion) == 1) + { + if($throw_exception) + throw new InvalidVersionConfigurationException('The minimum version cannot be greater version number than the maximum version'); + return False; + } + } + catch (Exception $e) + { + throw new RuntimeException('Version comparison failed: ' . $e->getMessage()); + } + + if(!in_array($this->Extension, CompilerExtensions::All)) + { + if($throw_exception) + throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported'); + return False; + } + + switch($this->Extension) + { + case CompilerExtensions::PHP: + if(!in_array($this->MaximumVersion, CompilerExtensionSupportedVersions::PHP)) + { + if($throw_exception) + throw new UnsupportedExtensionVersionException('The MaximumVersion does not support version ' . $this->MaximumVersion . ' for the extension ' . $this->Extension); + return False; + } + + if(!in_array($this->MinimumVersion, CompilerExtensionSupportedVersions::PHP)) + { + if($throw_exception) + throw new UnsupportedExtensionVersionException('The MinimumVersion does not support version ' . $this->MinimumVersion . ' for the extension ' . $this->Extension); + return False; + } + break; + + default: + throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported'); + } + + return True; + } + /** * Returns an array representation of the object * diff --git a/src/ncc/Objects/ProjectConfiguration/Project.php b/src/ncc/Objects/ProjectConfiguration/Project.php index a2a291b..8a22e2e 100644 --- a/src/ncc/Objects/ProjectConfiguration/Project.php +++ b/src/ncc/Objects/ProjectConfiguration/Project.php @@ -4,6 +4,10 @@ namespace ncc\Objects\ProjectConfiguration; + use ncc\Exceptions\InvalidPropertyValueException; + use ncc\Exceptions\RuntimeException; + use ncc\Exceptions\UnsupportedCompilerExtensionException; + use ncc\Exceptions\UnsupportedExtensionVersionException; use ncc\Utilities\Functions; /** @@ -31,6 +35,24 @@ $this->Options = []; } + /** + * Validates the Project object + * + * @param bool $throw_exception + * @return bool + * @throws InvalidPropertyValueException + * @throws RuntimeException + * @throws UnsupportedCompilerExtensionException + * @throws UnsupportedExtensionVersionException + */ + public function validate(bool $throw_exception=True): bool + { + if(!$this->Compiler->validate($throw_exception)) + return False; + + return True; + } + /** * Returns an array representation of the object *