Convert ExceptionCodes constants to enum cases

This commit is contained in:
netkas 2024-09-14 00:34:12 -04:00
parent 718c6ff8d8
commit e1013f6c15
16 changed files with 32 additions and 50 deletions

View file

@ -26,98 +26,80 @@
* @author Zi Xing Narrakas * @author Zi Xing Narrakas
* @copyright Copyright (C) 2022-2023. Nosial - All Rights Reserved. * @copyright Copyright (C) 2022-2023. Nosial - All Rights Reserved.
*/ */
final class ExceptionCodes enum ExceptionCodes : int
{ {
/** /**
* @see RuntimeException * @see RuntimeException
*/ */
public const RUNTIME = -1706; case RUNTIME = -1706;
/** /**
* @see BuildException * @see BuildException
*/ */
public const BUILD_EXCEPTION = -1727; case BUILD_EXCEPTION = -1727;
/** /**
* @see IOException * @see IOException
*/ */
public const IO_EXCEPTION = -1735; case IO_EXCEPTION = -1735;
/** /**
* @see ComposerException * @see ComposerException
*/ */
public const COMPOSER_EXCEPTION = -1749; case COMPOSER_EXCEPTION = -1749;
/** /**
* @see AuthenticationException * @see AuthenticationException
*/ */
public const AUTHENTICATION_EXCEPTION = -1760; case AUTHENTICATION_EXCEPTION = -1760;
/** /**
* @see NotSupportedException * @see NotSupportedException
*/ */
public const NOT_SUPPORTED_EXCEPTION = -1761; case NOT_SUPPORTED_EXCEPTION = -1761;
/** /**
* @see ArchiveException * @see ArchiveException
*/ */
public const ARCHIVE_EXCEPTION = -1764; case ARCHIVE_EXCEPTION = -1764;
/** /**
* @see PathNotFoundException * @see PathNotFoundException
*/ */
public const PATH_NOT_FOUND = -1769; case PATH_NOT_FOUND = -1769;
/** /**
* @see GitException * @see GitException
*/ */
public const GIT_EXCEPTION = -1770; case GIT_EXCEPTION = -1770;
/** /**
* @see ConfigurationException * @see ConfigurationException
*/ */
public const CONFIGURATION_EXCEPTION = -1772; case CONFIGURATION_EXCEPTION = -1772;
/** /**
* @see PackageException * @see PackageException
*/ */
public const PACKAGE_EXCEPTION = -1773; case PACKAGE_EXCEPTION = -1773;
/** /**
* @see NetworkException * @see NetworkException
*/ */
public const NETWORK_EXCEPTION = -1774; case NETWORK_EXCEPTION = -1774;
/** /**
* @see IntegrityException * @see IntegrityException
*/ */
public const INTEGRITY_EXCEPTION = -1775; case INTEGRITY_EXCEPTION = -1775;
/** /**
* @see OperationException * @see OperationException
*/ */
public const OPERATION_EXCEPTION = -1776; case OPERATION_EXCEPTION = -1776;
public const IMPORT_EXCEPTION = -1777;
/** /**
* All the exception codes from NCC * @see ImportException
*/ */
public const All = [ case IMPORT_EXCEPTION = -1777;
self::RUNTIME,
self::BUILD_EXCEPTION,
self::IO_EXCEPTION,
self::COMPOSER_EXCEPTION,
self::AUTHENTICATION_EXCEPTION,
self::NOT_SUPPORTED_EXCEPTION,
self::ARCHIVE_EXCEPTION,
self::PATH_NOT_FOUND,
self::GIT_EXCEPTION,
self::CONFIGURATION_EXCEPTION,
self::PACKAGE_EXCEPTION,
self::NETWORK_EXCEPTION,
self::INTEGRITY_EXCEPTION,
self::OPERATION_EXCEPTION,
self::IMPORT_EXCEPTION
];
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::ARCHIVE_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::ARCHIVE_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::AUTHENTICATION_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::AUTHENTICATION_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@ namespace ncc\Exceptions;
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::BUILD_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::BUILD_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@ namespace ncc\Exceptions;
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::COMPOSER_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::COMPOSER_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::CONFIGURATION_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::CONFIGURATION_EXCEPTION->value, $previous);
} }
} }

View file

@ -30,6 +30,6 @@
{ {
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::GIT_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::GIT_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@ namespace ncc\Exceptions;
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::IO_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::IO_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::IMPORT_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::IMPORT_EXCEPTION->value, $previous);
} }
} }

View file

@ -30,6 +30,6 @@
{ {
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::INTEGRITY_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::INTEGRITY_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::NETWORK_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::NETWORK_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::NOT_SUPPORTED_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::NOT_SUPPORTED_EXCEPTION->value, $previous);
} }
} }

View file

@ -30,6 +30,6 @@
{ {
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::OPERATION_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::OPERATION_EXCEPTION->value, $previous);
} }
} }

View file

@ -34,6 +34,6 @@
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::PACKAGE_EXCEPTION, $previous); parent::__construct($message, ExceptionCodes::PACKAGE_EXCEPTION->value, $previous);
} }
} }

View file

@ -41,7 +41,7 @@
*/ */
public function __construct(string $path, ?Throwable $previous = null) public function __construct(string $path, ?Throwable $previous = null)
{ {
parent::__construct(sprintf('Path "%s" not found', $path), ExceptionCodes::PATH_NOT_FOUND, $previous); parent::__construct(sprintf('Path "%s" not found', $path), ExceptionCodes::PATH_NOT_FOUND->value, $previous);
$this->path = $path; $this->path = $path;
} }

View file

@ -35,6 +35,6 @@ namespace ncc\Exceptions;
*/ */
public function __construct(string $message = "", ?Throwable $previous = null) public function __construct(string $message = "", ?Throwable $previous = null)
{ {
parent::__construct($message, ExceptionCodes::RUNTIME, $previous); parent::__construct($message, ExceptionCodes::RUNTIME->value, $previous);
} }
} }