- Removed unused exception GitCloneException in \ncc\Exceptions in favor of GitException

- Removed unused exception `GitCheckoutException` in `\ncc\Exceptions` in favor of `GitException`
 - Removed unused exception `GithubServiceException` in `\ncc\Exceptions` in favor of `GitException`
 - Updated `\ncc\Classes > GitClient > cloneRepository()` to throw `GitException` instead of `GitCloneException`
 - Updated `\ncc\Classes > GitClient > checkout()` to throw `GitException` instead of `GitCheckoutException`
 - Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions
This commit is contained in:
Netkas 2023-08-19 12:52:39 -04:00
parent c3406ca13f
commit 00dcc7e004
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
7 changed files with 78 additions and 128 deletions

View file

@ -15,6 +15,7 @@ features.
- Added new exception `PathNotFoundException` and implemented it in replacement for `DirectoryNotFoundException` and - Added new exception `PathNotFoundException` and implemented it in replacement for `DirectoryNotFoundException` and
`FileNotFoundException` in `\ncc\Exceptions` `FileNotFoundException` in `\ncc\Exceptions`
- Added a new interface class `BytecodeObjectInterface` which will be used to implement object types for compiled assets - Added a new interface class `BytecodeObjectInterface` which will be used to implement object types for compiled assets
- Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions
### Fixed ### Fixed
- Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()` - Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()`
@ -107,6 +108,8 @@ features.
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandle` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandle`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandlers` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandlers`
- Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration\Build > BuildConfiguration` - 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`
### Removed ### Removed
- Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions`
@ -114,6 +117,9 @@ features.
- Removed references of Win32 from the project as Windows is not going supported - Removed references of Win32 from the project as Windows is not going supported
- Removed unused exception `FileNotFoundException` in `\ncc\CLI > HelpMenu` - Removed unused exception `FileNotFoundException` in `\ncc\CLI > HelpMenu`
- Removed unused class `\ncc\Objects > SymlinkDictionary` - Removed unused class `\ncc\Objects > SymlinkDictionary`
- Removed unused exception `GitCloneException` in `\ncc\Exceptions` in favor of `GitException`
- Removed unused exception `GitCheckoutException` in `\ncc\Exceptions` in favor of `GitException`
- Removed unused exception `GithubServiceException` in `\ncc\Exceptions` in favor of `GitException`

View file

@ -26,7 +26,6 @@ ResourceNotFoundException
PACKAGE_NOT_FOUND PACKAGE_NOT_FOUND
VERSION_NOT_FOUND VERSION_NOT_FOUND
NO_AVAILABLE_UNITS NO_AVAILABLE_UNITS
PATH_NOT_FOUND
PackageException PackageException
UNSUPPORTED_PACKAGE UNSUPPORTED_PACKAGE
@ -53,8 +52,9 @@ ComposerException
COMPOSER_EXCEPTION COMPOSER_EXCEPTION
GitException GitException
GIT_CLONE_EXCEPTION * GIT_CLONE_EXCEPTION
GIT_CHECKOUT_EXCEPTION * GIT_CHECKOUT_EXCEPTION
* GITHUB_SERVICE_EXCEPTION
GITLAB_SERVICE_EXCEPTION GITLAB_SERVICE_EXCEPTION
GIT_TAGS_EXCEPTION GIT_TAGS_EXCEPTION

View file

@ -1,31 +1,29 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
namespace ncc\Classes; namespace ncc\Classes;
use ncc\Exceptions\GitCheckoutException; use ncc\Exceptions\GitException;
use ncc\Exceptions\GitCloneException;
use ncc\Exceptions\GitTagsException; use ncc\Exceptions\GitTagsException;
use ncc\Exceptions\InvalidScopeException;
use ncc\ThirdParty\Symfony\Process\Process; use ncc\ThirdParty\Symfony\Process\Process;
use ncc\Utilities\Console; use ncc\Utilities\Console;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
@ -37,8 +35,7 @@ namespace ncc\Classes;
* *
* @param string $url * @param string $url
* @return string * @return string
* @throws GitCloneException * @throws GitException
* @throws InvalidScopeException
*/ */
public static function cloneRepository(string $url): string public static function cloneRepository(string $url): string
{ {
@ -59,7 +56,7 @@ namespace ncc\Classes;
if (!$process->isSuccessful()) if (!$process->isSuccessful())
{ {
throw new GitCloneException($process->getErrorOutput()); throw new GitException(sprintf('Failed to clone repository %s: %s', $url, $process->getErrorOutput()));
} }
Console::outVerbose('Repository cloned to: ' . $path); Console::outVerbose('Repository cloned to: ' . $path);
@ -72,7 +69,7 @@ namespace ncc\Classes;
* *
* @param string $path * @param string $path
* @param string $branch * @param string $branch
* @throws GitCheckoutException * @throws GitException
*/ */
public static function checkout(string $path, string $branch): void public static function checkout(string $path, string $branch): void
{ {
@ -93,7 +90,7 @@ namespace ncc\Classes;
if (!$process->isSuccessful()) if (!$process->isSuccessful())
{ {
throw new GitCheckoutException($process->getErrorOutput()); throw new GitException(sprintf('Failed to checkout branch %s in repository %s: %s', $branch, $path, $process->getErrorOutput()));
} }
Console::outVerbose('Checked out branch: ' . $branch); Console::outVerbose('Checked out branch: ' . $branch);
@ -115,7 +112,7 @@ namespace ncc\Classes;
if (!$process->isSuccessful()) if (!$process->isSuccessful())
{ {
throw new GitCheckoutException($process->getErrorOutput()); throw new GitException(sprintf('Failed to update submodules in repository %s: %s', $path, $process->getErrorOutput()));
} }
Console::outVerbose('Submodules updated'); Console::outVerbose('Submodules updated');

View file

@ -1,32 +1,32 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * 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 * 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 * 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 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * 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 * 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 * 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 * 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 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
namespace ncc\Classes\GithubExtension; namespace ncc\Classes\GithubExtension;
use ncc\Enums\HttpRequestType; use ncc\Enums\HttpRequestType;
use ncc\Enums\Versions; use ncc\Enums\Versions;
use ncc\Classes\HttpClient; use ncc\Classes\HttpClient;
use ncc\Exceptions\AuthenticationException; use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\GithubServiceException; use ncc\Exceptions\GitException;
use ncc\Exceptions\GitlabServiceException; use ncc\Exceptions\GitlabServiceException;
use ncc\Exceptions\HttpException; use ncc\Exceptions\HttpException;
use ncc\Exceptions\MalformedJsonException; use ncc\Exceptions\MalformedJsonException;
@ -50,7 +50,7 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return RepositoryQueryResults * @return RepositoryQueryResults
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException * @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException
@ -83,7 +83,7 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return RepositoryQueryResults * @return RepositoryQueryResults
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException * @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException
@ -100,7 +100,7 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return RepositoryQueryResults * @return RepositoryQueryResults
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException * @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException
@ -119,7 +119,7 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return array * @return array
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException * @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException
@ -192,10 +192,10 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return array * @return array
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException
* @throws GitlabServiceException
*/ */
private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array
{ {
@ -208,7 +208,7 @@ namespace ncc\Classes\GithubExtension;
if ($response->StatusCode !== 200) if ($response->StatusCode !== 200)
{ {
throw new GithubServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode)); throw new GitException(sprintf('Github returned an error (%s): %s', $response->StatusCode, $response->Body));
} }
return Functions::loadJson($response->Body, Functions::FORCE_ARRAY); return Functions::loadJson($response->Body, Functions::FORCE_ARRAY);
@ -220,7 +220,7 @@ namespace ncc\Classes\GithubExtension;
* @param Entry|null $entry * @param Entry|null $entry
* @return mixed * @return mixed
* @throws AuthenticationException * @throws AuthenticationException
* @throws GithubServiceException * @throws GitException
* @throws GitlabServiceException * @throws GitlabServiceException
* @throws HttpException * @throws HttpException
* @throws MalformedJsonException * @throws MalformedJsonException

View file

@ -22,6 +22,7 @@
namespace ncc\Enums; namespace ncc\Enums;
use ncc\Exceptions\GitException;
use ncc\Exceptions\InvalidDependencyConfiguration; use ncc\Exceptions\InvalidDependencyConfiguration;
use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\PathNotFoundException;
use ncc\Exceptions\SymlinkException; use ncc\Exceptions\SymlinkException;
@ -283,16 +284,6 @@ namespace ncc\Enums;
*/ */
public const UNSUPPORTED_REMOTE_SOURCE_TYPE = -1753; public const UNSUPPORTED_REMOTE_SOURCE_TYPE = -1753;
/**
* @see GitCloneException
*/
public const GIT_CLONE_EXCEPTION = -1754;
/**
* @see GitCheckoutException
*/
public const GIT_CHECKOUT_EXCEPTION = -1755;
/** /**
* @see GitlabServiceException * @see GitlabServiceException
*/ */
@ -308,11 +299,6 @@ namespace ncc\Enums;
*/ */
public const GIT_TAGS_EXCEPTION = -1758; public const GIT_TAGS_EXCEPTION = -1758;
/**
* @see GithubServiceException
*/
public const GITHUB_SERVICE_EXCEPTION = -1759;
/** /**
* @see AuthenticationException * @see AuthenticationException
*/ */
@ -363,6 +349,11 @@ namespace ncc\Enums;
*/ */
public const PATH_NOT_FOUND = -1769; public const PATH_NOT_FOUND = -1769;
/**
* @see GitException
*/
public const GIT_EXCEPTION = -1770;
/** /**
* All the exception codes from NCC * All the exception codes from NCC
*/ */
@ -416,8 +407,6 @@ namespace ncc\Enums;
self::MISSING_DEPENDENCY, self::MISSING_DEPENDENCY,
self::HTTP_EXCEPTION, self::HTTP_EXCEPTION,
self::UNSUPPORTED_REMOTE_SOURCE_TYPE, self::UNSUPPORTED_REMOTE_SOURCE_TYPE,
self::GIT_CLONE_EXCEPTION,
self::GIT_CHECKOUT_EXCEPTION,
self::GITLAB_SERVICE_EXCEPTION, self::GITLAB_SERVICE_EXCEPTION,
self::GIT_TAGS_EXCEPTION, self::GIT_TAGS_EXCEPTION,
self::AUTHENTICATION_EXCEPTION, self::AUTHENTICATION_EXCEPTION,
@ -429,6 +418,7 @@ namespace ncc\Enums;
self::INVALID_BUILD_CONFIGURATION, self::INVALID_BUILD_CONFIGURATION,
self::INVALID_DEPENDENCY_CONFIGURATION, self::INVALID_DEPENDENCY_CONFIGURATION,
self::SYMLINK_EXCEPTION, self::SYMLINK_EXCEPTION,
self::PATH_NOT_FOUND self::PATH_NOT_FOUND,
self::GIT_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 GitCheckoutException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GIT_CHECKOUT_EXCEPTION, $previous);
}
}

View file

@ -1,5 +1,5 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
@ -20,20 +20,16 @@
* *
*/ */
namespace ncc\Exceptions; namespace ncc\Exceptions;
use Exception; use Exception;
use ncc\Enums\ExceptionCodes; use ncc\Enums\ExceptionCodes;
use Throwable; use Throwable;
class GitCloneException extends Exception class GitException extends Exception
{ {
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::GIT_CLONE_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::GIT_EXCEPTION, $previous);
} }
} }