diff --git a/CHANGELOG.md b/CHANGELOG.md index f2cf9cf..d25f8d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,7 @@ features. - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\Build > BuildConfiguration` - Updated `\ncc\Classes > GitClient > cloneRepository()` to throw `GitException` instead of `GitCloneException` - Updated `\ncc\Classes > GitClient > checkout()` to throw `GitException` instead of `GitCheckoutException` + - Corrected code-smell and code style issues in `\ncc\Objects > PackageLock` ### Removed - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` @@ -130,6 +131,15 @@ features. - Removed unused exception `UnsupportedPackageException` in `\ncc\Exceptions` (not used) - Removed unused exception `UnsupportedRemoteTypeSource` in `\ncc\Exceptions` (not used) - Removed unused exception `UnsupportedProjectTypeException` in `\ncc\Exceptions` (not used) + - Removed unused exception `InvalidProjectConfigurationException` in `\ncc\Exceptions` in favor of `ConfigurationException` + - Removed unused exception `InvalidScopeException` in `\ncc\Exceptions` in favor of `InvalidArgumentException` (standard php) + - Removed unused exception `InvalidCredentialsEntryException` in `\ncc\Exceptions` (not used) + - Removed unused exception `ComponentNotFoundException` in `\ncc\Exceptions` in favor of `ConfigurationException` + - Removed unused exception `InvalidPackageNameException` in `\ncc\Exceptions` (not used) + - Removed unused exception `InvalidVersionNumberException` in `\ncc\Exceptions` (not used) + - Removed unused exception `InvalidProjectException` in `\ncc\Exceptions` in favor of `ConfigurationException` + - Removed unused exception `InvalidProjectNameException` in `\ncc\Exceptions` in favor of `ConfigurationException` + - Removed unused exception `BuildConfigurationNotFoundException` in `\ncc\Exceptions` in favor of `ConfigurationException` diff --git a/scratch/exceptions_plan.txt b/scratch/exceptions_plan.txt index 53459de..fe043b1 100644 --- a/scratch/exceptions_plan.txt +++ b/scratch/exceptions_plan.txt @@ -1,11 +1,11 @@ ConfigurationException - INVALID_PROJECT_CONFIGURATION - INVALID_SCOPE - INVALID_CREDENTIALS_ENTRY - COMPONENT_VERSION_NOT_FOUND - INVALID_PACKAGE_NAME - INVALID_VERSION_NUMBER - INVALID_PROJECT_NAME + * INVALID_PROJECT_CONFIGURATION + * INVALID_SCOPE + * INVALID_CREDENTIALS_ENTRY + * COMPONENT_VERSION_NOT_FOUND + * INVALID_PACKAGE_NAME + * INVALID_VERSION_NUMBER + * INVALID_PROJECT_NAME BUILD_CONFIGURATION_NOT_FOUND INVALID_PROJECT_BUILD_CONFIGURATION INVALID_PROPERTY_VALUE diff --git a/src/ncc/CLI/Management/ConfigMenu.php b/src/ncc/CLI/Management/ConfigMenu.php index 7ef7c3e..be365bb 100644 --- a/src/ncc/CLI/Management/ConfigMenu.php +++ b/src/ncc/CLI/Management/ConfigMenu.php @@ -1,30 +1,30 @@ updateProperty($args['p'], $args['v'])) { $configuration_manager->save(); exit(0); } - else - { - Console::outError(sprintf('Unknown property %s', $args['p']), true, 1); - return; - } + + Console::outError(sprintf('Unknown property %s', $args['p']), true, 1); + return; } - else + + $value = $configuration_manager->getProperty($args['p']); + if(!is_null($value)) { - $value = $configuration_manager->getProperty($args['p']); - if(!is_null($value)) + if(is_bool($value)) { - if(is_bool($value)) - $value = ($value ? 'true' : 'false'); - if(is_array($value)) - $value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); - Console::out((string)$value); + $value = ($value ? 'true' : 'false'); } - exit(0); + + if(is_array($value)) + { + try + { + $value = json_encode($value, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); + } + catch(JsonException $e) + { + Console::outException(sprintf('Failed to encode array: %s', $e->getMessage()), $e, 1); + } + } + + Console::out((string)$value); } + exit(0); } self::displayOptions(); diff --git a/src/ncc/CLI/Management/ProjectMenu.php b/src/ncc/CLI/Management/ProjectMenu.php index 99289b2..91dec59 100644 --- a/src/ncc/CLI/Management/ProjectMenu.php +++ b/src/ncc/CLI/Management/ProjectMenu.php @@ -26,9 +26,7 @@ use ncc\Enums\CompilerExtensionDefaultVersions; use ncc\Enums\CompilerExtensions; use ncc\Enums\CompilerExtensionSupportedVersions; - use ncc\Exceptions\AccessDeniedException; - use ncc\Exceptions\InvalidPackageNameException; - use ncc\Exceptions\InvalidProjectNameException; + use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\PathNotFoundException; @@ -47,7 +45,6 @@ * * @param $args * @return void - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PathNotFoundException @@ -64,19 +61,19 @@ } /** + * Creates a new project + * * @param $args * @return void - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException - * @throws ProjectConfigurationNotFoundException * @throws PathNotFoundException + * @throws ProjectConfigurationNotFoundException */ public static function createProject($args): void { // First determine the source directory of the project $current_directory = getcwd(); - $real_src = $current_directory; if(isset($args['src'])) { // Make sure directory separators are corrected @@ -84,7 +81,7 @@ $args['src'] = str_ireplace('\\', DIRECTORY_SEPARATOR, $args['src']); // Remove the trailing slash - if(substr($args['src'], -1) == DIRECTORY_SEPARATOR) + if(substr($args['src'], -1) === DIRECTORY_SEPARATOR) { $args['src'] = substr($args['src'], 0, -1); } @@ -216,14 +213,9 @@ { $ProjectManager->initializeProject($Compiler, $project_name, $package_name, $real_src); } - catch (InvalidPackageNameException $e) + catch (ConfigurationException $e) { - Console::outException('The given package name is invalid, the value must follow the standard package naming convention', $e, 1); - return; - } - catch (InvalidProjectNameException $e) - { - Console::outException('The given project name is invalid, cannot be empty or larger than 126 characters', $e, 1); + Console::outException(sprintf('The project configuration is invalid: %s', $e->getMessage()), $e, 1); return; } catch (ProjectAlreadyExistsException $e) diff --git a/src/ncc/Enums/ExceptionCodes.php b/src/ncc/Enums/ExceptionCodes.php index 3d53113..e2535d1 100644 --- a/src/ncc/Enums/ExceptionCodes.php +++ b/src/ncc/Enums/ExceptionCodes.php @@ -28,16 +28,6 @@ */ final class ExceptionCodes { - /** - * @see InvalidProjectConfigurationException - */ - public const INVALID_PROJECT_CONFIGURATION = -1700; - - /** - * @see InvalidScopeException - */ - public const INVALID_SCOPE = -1703; - /** * @see AccessDeniedException */ @@ -53,36 +43,16 @@ */ public const RUNTIME = -1706; - /** - * @see InvalidCredentialsEntryException - */ - public const INVALID_CREDENTIALS_ENTRY = -1707; - - /** - * @see ComponentVersionNotFoundException - */ - public const COMPONENT_VERSION_NOT_FOUND = -1708; - /** * @see ConstantReadonlyException */ public const CONSTANT_READ_ONLY = -1709; - /** - * @see InvalidPackageNameException - */ - public const INVALID_PACKAGE_NAME = -1710; - /** * @see InvalidVersionNumberException */ public const INVALID_VERSION_NUMBER = -1711; - /** - * @see InvalidProjectNameException - */ - public const INVALID_PROJECT_NAME = -1712; - /** * @see ProjectAlreadyExistsException */ @@ -98,11 +68,6 @@ */ public const NO_UNITS_FOUND = -1715; - /** - * @see InvalidPackageException - */ - public const INVALID_PACKAGE = -1718; - /** * @see InvalidConstantNameException */ @@ -128,11 +93,6 @@ */ public const INVALID_PROPERTY_VALUE = -1724; - /** - * @see InvalidVersionConfigurationException - */ - public const INVALID_VERSION_CONFIGURATION = -1725; - /** * @see BuildException */ @@ -273,11 +233,6 @@ */ public const PACKAGE_FETCH_EXCEPTION = -1765; - /** - * @see InvalidBuildConfigurationException - */ - public const INVALID_BUILD_CONFIGURATION = -1766; - /** * @see InvalidDependencyConfiguration */ @@ -303,31 +258,28 @@ */ public const RESOURCE_NOT_FOUND = -1771; + /** + * @see ConfigurationException + */ + public const CONFIGURATION_EXCEPTION = -1772; + /** * All the exception codes from NCC */ public const All = [ - self::INVALID_PROJECT_CONFIGURATION, - self::INVALID_SCOPE, self::ACCESS_DENIED, self::MALFORMED_JSON, self::RUNTIME, - self::INVALID_CREDENTIALS_ENTRY, - self::COMPONENT_VERSION_NOT_FOUND, self::CONSTANT_READ_ONLY, - self::INVALID_PACKAGE_NAME, self::INVALID_VERSION_NUMBER, - self::INVALID_PROJECT_NAME, self::PROJECT_ALREADY_EXISTS, self::AUTOLOAD_GENERATOR, self::NO_UNITS_FOUND, - self::INVALID_PACKAGE, self::INVALID_CONSTANT_NAME, self::PACKAGE_PREPARATION_FAILED, self::BUILD_CONFIGURATION_NOT_FOUND, self::INVALID_PROJECT_BUILD_CONFIGURATION, self::INVALID_PROPERTY_VALUE, - self::INVALID_VERSION_CONFIGURATION, self::BUILD_EXCEPTION, self::PACKAGE_PARSING_EXCEPTION, self::PACKAGE_LOCK_EXCEPTION, @@ -354,11 +306,11 @@ self::NOT_SUPPORTED_EXCEPTION, self::ARCHIVE_EXCEPTION, self::PACKAGE_FETCH_EXCEPTION, - self::INVALID_BUILD_CONFIGURATION, self::INVALID_DEPENDENCY_CONFIGURATION, self::SYMLINK_EXCEPTION, self::PATH_NOT_FOUND, self::GIT_EXCEPTION, self::RESOURCE_NOT_FOUND, + self::CONFIGURATION_EXCEPTION ]; } \ No newline at end of file diff --git a/src/ncc/Exceptions/ComponentVersionNotFoundException.php b/src/ncc/Exceptions/ComponentVersionNotFoundException.php deleted file mode 100644 index f883f2d..0000000 --- a/src/ncc/Exceptions/ComponentVersionNotFoundException.php +++ /dev/null @@ -1,39 +0,0 @@ -property = $property; - } - - /** - * @return string|null - */ - public function getProperty(): ?string - { - return $this->property; - } - } \ No newline at end of file diff --git a/src/ncc/Exceptions/InvalidProjectNameException.php b/src/ncc/Exceptions/InvalidProjectNameException.php deleted file mode 100644 index e6c0718..0000000 --- a/src/ncc/Exceptions/InvalidProjectNameException.php +++ /dev/null @@ -1,39 +0,0 @@ -project_path . DIRECTORY_SEPARATOR . 'project.json')) @@ -217,7 +215,6 @@ * Attempts to load the project configuration * * @return void - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PathNotFoundException @@ -253,7 +250,6 @@ * Returns the ProjectConfiguration object * * @return ProjectConfiguration - * @throws AccessDeniedException * @throws IOException * @throws MalformedJsonException * @throws PathNotFoundException @@ -292,6 +288,7 @@ * @throws MalformedJsonException * @throws PathNotFoundException * @throws ProjectConfigurationNotFoundException + * @throws NotSupportedException */ public function build(string $build_configuration=BuildConfigurationValues::DEFAULT): string { diff --git a/src/ncc/Managers/RemoteSourcesManager.php b/src/ncc/Managers/RemoteSourcesManager.php index 8bf36b9..39703f0 100644 --- a/src/ncc/Managers/RemoteSourcesManager.php +++ b/src/ncc/Managers/RemoteSourcesManager.php @@ -26,7 +26,6 @@ use Exception; use ncc\Enums\Scopes; - use ncc\Exceptions\InvalidScopeException; use ncc\Exceptions\IOException; use ncc\Objects\DefinedRemoteSource; use ncc\Utilities\IO; @@ -52,12 +51,10 @@ /** * Public Constructor * - * @throws InvalidScopeException */ public function __construct() { $this->DefinedSourcesPath = PathFinder::getRemoteSources(Scopes::SYSTEM); - $this->load(); } diff --git a/src/ncc/Objects/NccVersionInformation/Component.php b/src/ncc/Objects/NccVersionInformation/Component.php index b7c9a7e..2fd7289 100644 --- a/src/ncc/Objects/NccVersionInformation/Component.php +++ b/src/ncc/Objects/NccVersionInformation/Component.php @@ -24,10 +24,10 @@ namespace ncc\Objects\NccVersionInformation; - use ncc\Exceptions\AccessDeniedException; - use ncc\Exceptions\ComponentVersionNotFoundException; use ncc\Exceptions\IOException; + use ncc\Exceptions\PathNotFoundException; use ncc\Utilities\IO; + use RuntimeException; class Component { @@ -49,9 +49,8 @@ * Attempts to resolve the component's build version * * @return string - * @throws ComponentVersionNotFoundException - * @throws AccessDeniedException * @throws IOException + * @throws PathNotFoundException */ public function getVersion(): string { @@ -60,7 +59,7 @@ if(!file_exists($component_path . 'VERSION')) { - throw new ComponentVersionNotFoundException('The file \'' . $component_path . 'VERSION' . '\' does not exist'); + throw new RuntimeException(sprintf('Component %s/%s does not have a VERSION stub file', $this->vendor, $this->package_name)); } return IO::fread($component_path . 'VERSION'); diff --git a/src/ncc/Objects/Package.php b/src/ncc/Objects/Package.php index e457d3a..9985ce5 100644 --- a/src/ncc/Objects/Package.php +++ b/src/ncc/Objects/Package.php @@ -27,8 +27,7 @@ use Exception; use ncc\Enums\EncoderType; use ncc\Enums\PackageStructureVersions; - use ncc\Exceptions\InvalidPackageException; - use ncc\Exceptions\InvalidProjectConfigurationException; + use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\IOException; use ncc\Exceptions\PackageParsingException; use ncc\Exceptions\PathNotFoundException; @@ -170,8 +169,7 @@ * * @param bool $throw_exception * @return bool - * @throws InvalidPackageException - * @throws InvalidProjectConfigurationException + * @throws ConfigurationException */ public function validate(bool $throw_exception=True): bool { @@ -180,7 +178,7 @@ { if($throw_exception) { - throw new InvalidPackageException('The MagicBytes property is required and cannot be null'); + throw new ConfigurationException('The MagicBytes property is required and cannot be null'); } return false; @@ -191,7 +189,7 @@ { if($throw_exception) { - throw new InvalidPackageException('The Assembly property is required and cannot be null'); + throw new ConfigurationException('The Assembly property is required and cannot be null'); } return false; diff --git a/src/ncc/Objects/PackageLock.php b/src/ncc/Objects/PackageLock.php index e1dc7cd..2d3b975 100644 --- a/src/ncc/Objects/PackageLock.php +++ b/src/ncc/Objects/PackageLock.php @@ -1,32 +1,30 @@ Packages[$package]->removeVersion($version); // Remove the entire package entry if there's no installed versions - if($this->Packages[$package]->getLatestVersion() == null && $r) + if($r && $this->Packages[$package]->getLatestVersion() === null) { unset($this->Packages[$package]); } @@ -162,13 +158,7 @@ public function getPackage(string $package): ?PackageEntry { Console::outDebug(sprintf('getting package %s from package lock file', $package)); - - if(isset($this->Packages[$package])) - { - return $this->Packages[$package]; - } - - return null; + return $this->Packages[$package] ?? null; } /** @@ -181,8 +171,11 @@ public function packageExists(string $package, ?string $version=null): bool { $package_entry = $this->getPackage($package); - if($package_entry == null) + + if($package_entry === null) + { return false; + } if($version !== null) { @@ -196,7 +189,7 @@ return false; } - if($version_entry == null) + if($version_entry === null) { return false; } @@ -213,8 +206,12 @@ public function getPackages(): array { $results = []; + foreach($this->Packages as $package => $entry) + { $results[$package] = $entry->getVersions(); + } + return $results; } diff --git a/src/ncc/Objects/PackageLock/PackageEntry.php b/src/ncc/Objects/PackageLock/PackageEntry.php index c85ea22..3391708 100644 --- a/src/ncc/Objects/PackageLock/PackageEntry.php +++ b/src/ncc/Objects/PackageLock/PackageEntry.php @@ -26,8 +26,7 @@ use ncc\Enums\Scopes; use ncc\Enums\Versions; - use ncc\Exceptions\InvalidPackageNameException; - use ncc\Exceptions\InvalidScopeException; + use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\VersionNotFoundException; use ncc\Objects\Package; use ncc\Objects\ProjectConfiguration\UpdateSource; @@ -246,8 +245,7 @@ /** * @return string - * @throws InvalidPackageNameException - * @throws InvalidScopeException + * @throws ConfigurationException */ public function getDataPath(): string { diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index 81a4828..75cfa13 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -27,10 +27,9 @@ use Exception; use ncc\Enums\Options\BuildConfigurationValues; use ncc\Exceptions\BuildConfigurationNotFoundException; - use ncc\Exceptions\InvalidBuildConfigurationException; + use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\InvalidConstantNameException; use ncc\Exceptions\InvalidProjectBuildConfiguration; - use ncc\Exceptions\InvalidProjectConfigurationException; use ncc\Exceptions\InvalidPropertyValueException; use ncc\Exceptions\IOException; use ncc\Exceptions\MalformedJsonException; @@ -104,13 +103,10 @@ * @param bool $throw_exception * @return bool * @throws BuildConfigurationNotFoundException - * @throws InvalidConstantNameException - * @throws InvalidProjectBuildConfiguration - * @throws InvalidProjectConfigurationException + * @throws ConfigurationException * @throws InvalidPropertyValueException * @throws RuntimeException * @throws UndefinedExecutionPolicyException - * @throws InvalidBuildConfigurationException */ public function validate(bool $throw_exception=True): bool { @@ -180,7 +176,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('Build configuration build.main cannot be set to "%s"', BuildConfigurationValues::ALL)); + throw new ConfigurationException(sprintf('Build configuration build.main cannot be set to "%s"', BuildConfigurationValues::ALL)); } return false; diff --git a/src/ncc/Objects/ProjectConfiguration/Assembly.php b/src/ncc/Objects/ProjectConfiguration/Assembly.php index bbef8a5..a846425 100644 --- a/src/ncc/Objects/ProjectConfiguration/Assembly.php +++ b/src/ncc/Objects/ProjectConfiguration/Assembly.php @@ -25,7 +25,7 @@ namespace ncc\Objects\ProjectConfiguration; use ncc\Enums\RegexPatterns; - use ncc\Exceptions\InvalidProjectConfigurationException; + use ncc\Exceptions\ConfigurationException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Utilities\Functions; use ncc\Utilities\Validate; @@ -102,7 +102,7 @@ * * @param bool $throw_exception * @return bool - * @throws InvalidProjectConfigurationException + * @throws ConfigurationException */ public function validate(bool $throw_exception=True): bool { @@ -110,7 +110,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The UUID is not a valid v4 UUID', 'Assembly.UUID'); + throw new ConfigurationException(sprintf('The UUID is not a valid v4 UUID: %s, in property Assembly.UUID', $this->uuid)); } return false; @@ -120,7 +120,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The version number is invalid', 'Assembly.Version'); + throw new ConfigurationException(sprintf('The version number is invalid: %s, in property Assembly.Version', $this->version)); } return false; @@ -130,7 +130,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The package name is invalid', 'Assembly.Package'); + throw new ConfigurationException(sprintf('The package name is invalid: %s, in property Assembly.Package', $this->package)); } return false; @@ -140,7 +140,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The name cannot be larger than 126 characters', 'Assembly.Name'); + throw new ConfigurationException(sprintf('The name cannot be larger than 126 characters: %s, in property Assembly.Name', $this->name)); } return false; @@ -150,7 +150,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The description cannot be larger than 512 characters', 'Assembly.Description'); + throw new ConfigurationException(sprintf('The description cannot be larger than 512 characters: %s, in property Assembly.Description', $this->description)); } return false; @@ -160,7 +160,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The company cannot be larger than 126 characters', 'Assembly.Company'); + throw new ConfigurationException(sprintf('The company cannot be larger than 126 characters: %s, in property Assembly.Company', $this->company)); } return false; @@ -170,7 +170,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The company cannot be larger than 256 characters', 'Assembly.Product'); + throw new ConfigurationException(sprintf('The product cannot be larger than 256 characters: %s, in property Assembly.Product', $this->product)); } return false; @@ -180,7 +180,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The copyright cannot be larger than 256 characters', 'Assembly.Copyright'); + throw new ConfigurationException(sprintf('The copyright cannot be larger than 256 characters: %s, in property Assembly.Copyright', $this->company)); } return false; @@ -190,7 +190,7 @@ { if($throw_exception) { - throw new InvalidProjectConfigurationException('The trademark cannot be larger than 256 characters', 'Assembly.Trademark'); + throw new ConfigurationException(sprintf('The trademark cannot be larger than 256 characters: %s, in property Assembly.Trademark', $this->trademark)); } return false; diff --git a/src/ncc/Objects/ProjectConfiguration/Build.php b/src/ncc/Objects/ProjectConfiguration/Build.php index e35952b..fc797f3 100644 --- a/src/ncc/Objects/ProjectConfiguration/Build.php +++ b/src/ncc/Objects/ProjectConfiguration/Build.php @@ -26,9 +26,7 @@ use ncc\Enums\Options\BuildConfigurationValues; use ncc\Exceptions\BuildConfigurationNotFoundException; - use ncc\Exceptions\InvalidBuildConfigurationException; - use ncc\Exceptions\InvalidConstantNameException; - use ncc\Exceptions\InvalidProjectBuildConfiguration; + use ncc\Exceptions\ConfigurationException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Objects\ProjectConfiguration\Build\BuildConfiguration; use ncc\Utilities\Functions; @@ -173,9 +171,7 @@ * @param bool $throw_exception * @return bool * @throws BuildConfigurationNotFoundException - * @throws InvalidBuildConfigurationException - * @throws InvalidConstantNameException - * @throws InvalidProjectBuildConfiguration + * @throws ConfigurationException */ public function validate(bool $throw_exception=True): bool { @@ -184,7 +180,7 @@ { if(!Validate::constantName($name)) { - throw new InvalidConstantNameException('The name \'' . $name . '\' is not valid for a constant declaration, '); + throw new ConfigurationException(sprintf('The name "%s" is not valid for a constant declaration', $name)); } } @@ -196,7 +192,7 @@ { if($throw_exception) { - throw new InvalidProjectBuildConfiguration('The build configuration \'' . $configuration->name . '\' is already defined, build configuration names must be unique'); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $configuration->name)); } return false; @@ -205,16 +201,9 @@ foreach($this->build_configurations as $configuration) { - try + if (!$configuration->validate($throw_exception)) { - if (!$configuration->validate($throw_exception)) - { - return false; - } - } - catch (InvalidBuildConfigurationException $e) - { - throw new InvalidBuildConfigurationException(sprintf('Error in build configuration \'%s\'', $configuration->name), $e); + return false; } } @@ -222,7 +211,7 @@ { if($throw_exception) { - throw new InvalidProjectBuildConfiguration('The default build configuration is not set'); + throw new ConfigurationException('The default build configuration is not set'); } return false; @@ -232,7 +221,7 @@ { if($throw_exception) { - throw new InvalidProjectBuildConfiguration('The default build configuration name \'' . $this->default_configuration . '\' is not valid'); + throw new ConfigurationException(sprintf('The default build configuration name "%s" is not valid', $this->default_configuration)); } return false; diff --git a/src/ncc/Objects/ProjectConfiguration/Build/BuildConfiguration.php b/src/ncc/Objects/ProjectConfiguration/Build/BuildConfiguration.php index d388653..e3bfdcd 100644 --- a/src/ncc/Objects/ProjectConfiguration/Build/BuildConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration/Build/BuildConfiguration.php @@ -24,8 +24,7 @@ namespace ncc\Objects\ProjectConfiguration\Build; - use ncc\Exceptions\InvalidBuildConfigurationException; - use ncc\Exceptions\InvalidDependencyConfiguration; + use ncc\Exceptions\ConfigurationException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Objects\ProjectConfiguration\Dependency; use ncc\Utilities\Functions; @@ -113,7 +112,7 @@ * * @param bool $throw_exception * @return bool - * @throws InvalidBuildConfigurationException + * @throws ConfigurationException */ public function validate(bool $throw_exception=True): bool { @@ -121,7 +120,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -131,7 +130,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'output_path\' contains an invalid path name in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -141,7 +140,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'define_constants\' must be an array in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -151,7 +150,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'exclude_files\' must be an array in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -161,7 +160,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'pre_build\' must be an array in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -171,7 +170,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'post_build\' must be an array in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -181,7 +180,7 @@ { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('\'dependencies\' must be an array in %s', $this->name)); + throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $this->name)); } return False; @@ -197,11 +196,11 @@ return False; } } - catch (InvalidDependencyConfiguration $e) + catch (ConfigurationException $e) { if($throw_exception) { - throw new InvalidBuildConfigurationException(sprintf('Invalid dependency configuration in %s: %s', $this->name, $e->getMessage())); + throw $e; } return False; diff --git a/src/ncc/Objects/ProjectConfiguration/Compiler.php b/src/ncc/Objects/ProjectConfiguration/Compiler.php index 00de50b..53b639e 100644 --- a/src/ncc/Objects/ProjectConfiguration/Compiler.php +++ b/src/ncc/Objects/ProjectConfiguration/Compiler.php @@ -27,10 +27,9 @@ use Exception; use ncc\Enums\CompilerExtensions; use ncc\Enums\CompilerExtensionSupportedVersions; + use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\InvalidPropertyValueException; - use ncc\Exceptions\InvalidVersionConfigurationException; use ncc\Exceptions\NotSupportedException; - use ncc\Exceptions\RuntimeException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\ThirdParty\jelix\Version\VersionComparator; use ncc\Utilities\Functions; @@ -67,9 +66,9 @@ * * @param bool $throw_exception * @return bool + * @throws ConfigurationException * @throws InvalidPropertyValueException * @throws NotSupportedException - * @throws RuntimeException */ public function validate(bool $throw_exception=True): bool { @@ -109,7 +108,7 @@ { if($throw_exception) { - throw new InvalidVersionConfigurationException('The minimum version cannot be greater version number than the maximum version'); + throw new ConfigurationException('The minimum version cannot be greater version number than the maximum version'); } return False; @@ -117,7 +116,7 @@ } catch (Exception $e) { - throw new RuntimeException('Version comparison failed: ' . $e->getMessage()); + throw new ConfigurationException('Version comparison failed: ' . $e->getMessage()); } if(!in_array($this->extension, CompilerExtensions::ALL)) diff --git a/src/ncc/Objects/ProjectConfiguration/Dependency.php b/src/ncc/Objects/ProjectConfiguration/Dependency.php index 9d23183..ba2bcb9 100644 --- a/src/ncc/Objects/ProjectConfiguration/Dependency.php +++ b/src/ncc/Objects/ProjectConfiguration/Dependency.php @@ -24,7 +24,7 @@ namespace ncc\Objects\ProjectConfiguration; - use ncc\Exceptions\InvalidDependencyConfiguration; + use ncc\Exceptions\ConfigurationException; use ncc\Interfaces\BytecodeObjectInterface; use ncc\Utilities\Functions; use ncc\Utilities\Validate; @@ -68,7 +68,7 @@ * * @param bool $throw_exception * @return bool - * @throws InvalidDependencyConfiguration + * @throws ConfigurationException */ public function validate(bool $throw_exception): bool { @@ -76,7 +76,7 @@ { if($throw_exception) { - throw new InvalidDependencyConfiguration(sprintf('Invalid dependency name "%s"', $this->name)); + throw new ConfigurationException(sprintf('Invalid dependency name "%s"', $this->name)); } return false; @@ -86,7 +86,7 @@ { if($throw_exception) { - throw new InvalidDependencyConfiguration(sprintf('Invalid dependency version "%s"', $this->version)); + throw new ConfigurationException(sprintf('Invalid dependency version "%s"', $this->version)); } return false; diff --git a/src/ncc/Runtime.php b/src/ncc/Runtime.php index 6e288d3..f18051b 100644 --- a/src/ncc/Runtime.php +++ b/src/ncc/Runtime.php @@ -174,8 +174,6 @@ * * @param string $package * @return string - * @throws Exceptions\InvalidPackageNameException - * @throws Exceptions\InvalidScopeException * @throws PackageLockException * @throws PackageNotFoundException */ diff --git a/src/ncc/Utilities/PathFinder.php b/src/ncc/Utilities/PathFinder.php index 615f0c0..21bc5a4 100644 --- a/src/ncc/Utilities/PathFinder.php +++ b/src/ncc/Utilities/PathFinder.php @@ -1,31 +1,30 @@