From 405f53673ac15e19b35f5387827ff4725fad33cb Mon Sep 17 00:00:00 2001 From: Netkas Date: Sat, 17 Dec 2022 09:50:34 -0500 Subject: [PATCH] Added method \ncc\Objects\ProjectConfiguration > Dependency > validate() https://git.n64.cc/nosial/ncc/-/issues/4 --- .../ProjectConfiguration/Dependency.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ncc/Objects/ProjectConfiguration/Dependency.php b/src/ncc/Objects/ProjectConfiguration/Dependency.php index 6978740..067f785 100644 --- a/src/ncc/Objects/ProjectConfiguration/Dependency.php +++ b/src/ncc/Objects/ProjectConfiguration/Dependency.php @@ -5,7 +5,9 @@ namespace ncc\Objects\ProjectConfiguration; use ncc\Abstracts\DependencySourceType; + use ncc\Exceptions\InvalidDependencyConfiguration; use ncc\Utilities\Functions; + use ncc\Utilities\Validate; /** * @author Zi Xing Narrakas @@ -84,4 +86,32 @@ return $DependencyObject; } + + /** + * Validates the dependency configuration + * + * @param bool $throw_exception + * @return bool + * @throws InvalidDependencyConfiguration + */ + public function validate(bool $throw_exception): bool + { + if(!Validate::packageName($this->Name)) + { + if($throw_exception) + throw new InvalidDependencyConfiguration(sprintf('Invalid dependency name "%s"', $this->Name)); + + return false; + } + + if($this->Version !== null && !Validate::version($this->Version)) + { + if($throw_exception) + throw new InvalidDependencyConfiguration(sprintf('Invalid dependency version "%s"', $this->Version)); + + return false; + } + + return true; + } } \ No newline at end of file