- Corrected code-smell and code style issues in \ncc\Objects > PackageLock

- 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`
This commit is contained in:
Netkas 2023-08-21 18:49:09 -04:00
parent c151d29b46
commit 0f08bd54d4
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
31 changed files with 258 additions and 668 deletions

View file

@ -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`

View file

@ -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

View file

@ -1,30 +1,30 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\CLI\Management;
namespace ncc\CLI\Management;
use JsonException;
use ncc\Enums\Scopes;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\IOException;
use ncc\Managers\ConfigurationManager;
use ncc\Objects\CliHelpSection;
@ -42,7 +42,6 @@ namespace ncc\CLI\Management;
* @return void
* @throws AccessDeniedException
* @throws IOException
* @throws InvalidScopeException
*/
public static function start($args): void
{
@ -55,7 +54,8 @@ namespace ncc\CLI\Management;
return;
}
$handle = fopen($sample_file, 'r');
$handle = fopen($sample_file, 'rb');
if (!$handle)
{
Console::outError('Cannot display sample, error reading template_config.yaml', true, 1);
@ -79,7 +79,7 @@ namespace ncc\CLI\Management;
return;
}
$handle = fopen(PathFinder::getConfigurationFile(), 'r');
$handle = fopen(PathFinder::getConfigurationFile(), 'rb');
if (!$handle)
{
Console::outError('Cannot display configuration file, error reading file', true, 1);
@ -107,32 +107,44 @@ namespace ncc\CLI\Management;
return;
}
if(strtolower($args['v']) == 'null')
if(strtolower($args['v']) === 'null')
{
$args['v'] = null;
}
if($configuration_manager->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();

View file

@ -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)

View file

@ -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
];
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class ComponentVersionNotFoundException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::COMPONENT_VERSION_NOT_FOUND, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class ConfigurationException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::CONFIGURATION_EXCEPTION, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidBuildConfigurationException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_BUILD_CONFIGURATION, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidCredentialsEntryException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_CREDENTIALS_ENTRY, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidPackageException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_PACKAGE, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidPackageNameException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_PACKAGE_NAME, $previous);
}
}

View file

@ -1,58 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
/**
* @author Zi Xing Narrakas
* @copyright Copyright (C) 2022-2022. Nosial - All Rights Reserved.
*/
class InvalidProjectConfigurationException extends Exception
{
/**
* @var string|null
*/
private ?string $property;
/**
* @param string $message
* @param string|null $property
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?string $property=null, ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_PROJECT_CONFIGURATION, $previous);
$this->property = $property;
}
/**
* @return string|null
*/
public function getProperty(): ?string
{
return $this->property;
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidProjectNameException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_PROJECT_NAME, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidScopeException extends Exception
{
/**
* @param string $scope
* @param Throwable|null $previous
*/
public function __construct(string $scope = "", ?Throwable $previous = null)
{
parent::__construct('The given scope \'' . $scope . '\' is not valid', ExceptionCodes::INVALID_SCOPE, $previous);
}
}

View file

@ -1,39 +0,0 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class InvalidVersionConfigurationException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::INVALID_VERSION_CONFIGURATION, $previous);
}
}

View file

@ -27,8 +27,8 @@
use Exception;
use ncc\Enums\Scopes;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException;
use ncc\ThirdParty\Symfony\Yaml\Yaml;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
@ -47,9 +47,8 @@
private $configuration;
/**
* @throws AccessDeniedException
* @throws IOException
* @throws InvalidScopeException
* @throws PathNotFoundException
*/
public function __construct()
{
@ -60,9 +59,8 @@
* Loads the configuration file if it exists
*
* @return void
* @throws AccessDeniedException
* @throws IOException
* @throws InvalidScopeException
* @throws PathNotFoundException
*/
public function load(): void
{
@ -86,7 +84,6 @@
* @return void
* @throws AccessDeniedException
* @throws IOException
* @throws InvalidScopeException
*/
public function save(): void
{
@ -147,7 +144,6 @@
* @return bool
* @throws AccessDeniedException
* @throws IOException
* @throws InvalidScopeException
*/
public function updateProperty(string $property, $value): bool
{

View file

@ -1,24 +1,24 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
@ -40,8 +40,6 @@
use ncc\CLI\Main;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\InstallationException;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\MissingDependencyException;
use ncc\Exceptions\NotSupportedException;
@ -108,8 +106,6 @@
* @throws AccessDeniedException
* @throws IOException
* @throws InstallationException
* @throws InvalidPackageNameException
* @throws InvalidScopeException
* @throws MissingDependencyException
* @throws NotSupportedException
* @throws PackageAlreadyInstalledException
@ -655,8 +651,6 @@
* @throws AccessDeniedException
* @throws IOException
* @throws InstallationException
* @throws InvalidPackageNameException
* @throws InvalidScopeException
* @throws MissingDependencyException
* @throws NotSupportedException
* @throws PackageAlreadyInstalledException

View file

@ -31,10 +31,10 @@
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\BuildConfigurationNotFoundException;
use ncc\Exceptions\BuildException;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidProjectNameException;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\MalformedJsonException;
use ncc\Exceptions\NotSupportedException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Exceptions\ProjectAlreadyExistsException;
use ncc\Exceptions\ProjectConfigurationNotFoundException;
@ -71,7 +71,6 @@
* Public Constructor
*
* @param string $path
* @throws AccessDeniedException
* @throws IOException
* @throws MalformedJsonException
* @throws PathNotFoundException
@ -108,8 +107,7 @@
* @param string $package
* @param string|null $src
* @param array $options
* @throws InvalidPackageNameException
* @throws InvalidProjectNameException
* @throws ConfigurationException
* @throws MalformedJsonException
* @throws ProjectAlreadyExistsException
*/
@ -118,12 +116,12 @@
// Validate the project information first
if(!Validate::packageName($package))
{
throw new InvalidPackageNameException('The given package name \'' . $package . '\' is not a valid package name');
throw new ConfigurationException('The given package name \'' . $package . '\' is not a valid package name');
}
if(!Validate::projectName($name))
{
throw new InvalidProjectNameException('The given project name \'' . $name . '\' is not valid');
throw new ConfigurationException('The given project name \'' . $name . '\' is not valid');
}
if(file_exists($this->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
{

View file

@ -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();
}

View file

@ -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');

View file

@ -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;

View file

@ -1,32 +1,30 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects;
use ncc\Enums\Versions;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Objects\PackageLock\PackageEntry;
use ncc\Utilities\Console;
@ -79,8 +77,6 @@
* @param Package $package
* @param string $install_path
* @return void
* @throws InvalidPackageNameException
* @throws InvalidScopeException
*/
public function addPackage(Package $package, string $install_path): void
{
@ -121,7 +117,7 @@
$r = $this->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;
}

View file

@ -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
{

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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))

View file

@ -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;

View file

@ -174,8 +174,6 @@
*
* @param string $package
* @return string
* @throws Exceptions\InvalidPackageNameException
* @throws Exceptions\InvalidScopeException
* @throws PackageLockException
* @throws PackageNotFoundException
*/

View file

@ -1,31 +1,30 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Utilities;
namespace ncc\Utilities;
use InvalidArgumentException;
use ncc\Enums\Scopes;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\RunnerExecutionException;
use ncc\ThirdParty\Symfony\Process\ExecutableFinder;
@ -46,7 +45,6 @@ namespace ncc\Utilities;
*
* @param string $scope
* @return string
* @throws InvalidScopeException
*/
public static function getHomePath(string $scope=Scopes::AUTO): string
{
@ -54,7 +52,7 @@ namespace ncc\Utilities;
if(!Validate::scope($scope, false))
{
throw new InvalidScopeException($scope);
throw new InvalidArgumentException(sprintf('Invalid access scope "%s"', $scope));
}
switch($scope)
@ -67,7 +65,7 @@ namespace ncc\Utilities;
return posix_getpwuid(0)['dir'] . DIRECTORY_SEPARATOR . '.ncc';
}
throw new InvalidScopeException($scope);
throw new InvalidArgumentException(sprintf('Invalid access scope "%s"', $scope));
}
/**
@ -183,13 +181,13 @@ namespace ncc\Utilities;
*
* @param string $package
* @return string
* @throws InvalidPackageNameException
* @throws ConfigurationException
*/
public static function getPackageDataPath(string $package): string
{
if(!Validate::packageName($package))
{
throw new InvalidPackageNameException($package);
throw new ConfigurationException($package);
}
return self::getDataPath(Scopes::SYSTEM) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . $package;