Skip to content

Commit

Permalink
Updated documentation and added defined codes for each exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tlmcclatchey committed Feb 17, 2024
1 parent f44a3e7 commit 0be6ae3
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 172 deletions.
34 changes: 19 additions & 15 deletions src/Exceptions/CallFailedException.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

/**
* Represents an exception thrown when a function call fails during dependency injection.
*
* This exception is used specifically when a call to a function or method fails within the dependency injection process,
* indicating problems with invoking the desired functionality.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when a call to a function fails.
*/
class CallFailedException extends Exception
class CallFailedException extends DependencyInjectionException
{
/**
* CallFailedException constructor.
*
* @param string $function The function that failed to be called.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $function, int $code = 0, ?Throwable $previous = null)
public function __construct(string $function, ?Throwable $previous = null)
{
parent::__construct("Call to function $function failed.", $code, $previous);
parent::__construct("Call to function $function failed.", $previous);
$this->code = 1501;
}
}
}
34 changes: 19 additions & 15 deletions src/Exceptions/ClassNotDefinedException.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

/**
* Represents an exception thrown when a specified class is not defined.
*
* This exception indicates that the class intended for instantiation or usage within the dependency injection process
* does not exist, highlighting issues with class resolution.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when a class is not defined.
*/
class ClassNotDefinedException extends Exception
class ClassNotDefinedException extends DependencyInjectionException
{
/**
* ClassNotDefinedException constructor.
*
* @param string $class The class that is not defined.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, ?Throwable $previous = null)
{
parent::__construct("The class $class is not defined.", $code, $previous);
parent::__construct("The class $class is not defined.", $previous);
$this->code = 1502;
}
}
}
34 changes: 19 additions & 15 deletions src/Exceptions/ClassNotInstantiableException.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

/**
* Represents an exception thrown when a class cannot be instantiated.
*
* This exception is used to signal that a class, which is required to be instantiated as part of the dependency
* injection process, is not instantiable, often due to it being abstract or an interface.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when a class is not instantiable.
*/
class ClassNotInstantiableException extends Exception
class ClassNotInstantiableException extends DependencyInjectionException
{
/**
* ClassNotInstantiableException constructor.
*
* @param string $class The class that is not instantiable.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, ?Throwable $previous = null)
{
parent::__construct("The class $class is not instantiable.", $code, $previous);
parent::__construct("The class $class is not instantiable.", $previous);
$this->code = 1503;
}
}
}
35 changes: 19 additions & 16 deletions src/Exceptions/InstantiateCircularReferenceException.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

/**
* Represents an exception thrown due to a circular reference detected during instantiation.
*
* This exception indicates a circular dependency within the instantiation process, which prevents successful
* dependency injection due to the recursion loop.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when a circular reference is detected during class instantiation.
*/
class InstantiateCircularReferenceException extends Exception
class InstantiateCircularReferenceException extends DependencyInjectionException
{
/**
* InstantiateCircularReferenceException constructor.
*
* @param string $class The class for which a circular reference was detected.
* @param string $stack The instantiation stack that caused the circular reference.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, string $stack, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, string $stack, ?Throwable $previous = null)
{
parent::__construct("Circular reference detected during instantiation of the class $class. Instantiation stack: $stack.", $code, $previous);
parent::__construct("Circular reference detected during instantiation of the class $class. Instantiation stack: $stack.", $previous);
$this->code = 1504;
}
}
}
34 changes: 19 additions & 15 deletions src/Exceptions/InstantiationFailedException.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php

/**
* Represents an exception thrown when a class cannot be instantiated as required.
*
* This exception signals a failure in the instantiation process of a class, indicating an inability to create an
* instance due to various potential issues.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when the instantiation of a class fails.
*/
class InstantiationFailedException extends Exception
class InstantiationFailedException extends DependencyInjectionException
{
/**
* InstantiationFailedException constructor.
*
* @param string $class The class that failed to be instantiated.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, ?Throwable $previous = null)
{
parent::__construct("Failed to instantiate the class $class.", $code, $previous);
parent::__construct("Failed to instantiate the class $class.", $previous);
$this->code = 1505;
}
}
}
35 changes: 19 additions & 16 deletions src/Exceptions/InvocationFailedException.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

/**
* Represents an exception thrown when a method invocation fails.
*
* This exception is thrown to indicate that an attempt to invoke a method on a class instance failed during the
* dependency injection process, signaling invocation-related issues.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when the invocation of a method fails.
*/
class InvocationFailedException extends Exception
class InvocationFailedException extends DependencyInjectionException
{
/**
* InvocationFailedException constructor.
*
* @param string $class The class in which the method invocation failed.
* @param string $method The method that failed to be invoked.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, string $method, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, string $method, ?Throwable $previous = null)
{
parent::__construct("Invocation of method $method in class $class failed.", $code, $previous);
parent::__construct("Invocation of method $method in class $class failed.", $previous);
$this->code = 1506;
}
}
}
35 changes: 19 additions & 16 deletions src/Exceptions/MethodIsStaticException.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

/**
* Represents an exception thrown when an attempt is made to non-statically invoke a static method.
*
* This exception indicates a misuse of a static method within the dependency injection process, particularly when an
* attempt is made to invoke it in a non-static context.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when attempting to invoke a static method.
*/
class MethodIsStaticException extends Exception
class MethodIsStaticException extends DependencyInjectionException
{
/**
* MethodIsStaticException constructor.
*
* @param string $class The class in which the method is declared.
* @param string $method The static method that cannot be invoked.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, string $method, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, string $method, ?Throwable $previous = null)
{
parent::__construct("The method $method in class $class is static.", $code, $previous);
parent::__construct("The method $method in class $class is static.", $previous);
$this->code = 1507;
}
}
}
35 changes: 19 additions & 16 deletions src/Exceptions/MethodNotDefinedException.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

/**
* Represents an exception thrown when a specified method is not defined in a class.
*
* This exception is thrown to indicate the absence of a required method in a class, highlighting a potential
* misconfiguration or typo in the method name within the dependency injection process.
*
* @package CommonPHP
* @subpackage DependencyInjection\Exceptions
* @author Timothy McClatchey <timothy@commonphp.org>
* @copyright 2024 CommonPHP.org
* @license http://opensource.org/licenses/MIT MIT License
* @noinspection PhpUnused
*/

namespace CommonPHP\DependencyInjection\Exceptions;

use Exception;
use Throwable;

/**
* Exception thrown when a method is not defined in a class.
*/
class MethodNotDefinedException extends Exception
class MethodNotDefinedException extends DependencyInjectionException
{
/**
* MethodNotDefinedException constructor.
*
* @param string $class The class in which the method is not defined.
* @param string $method The method that is not defined.
* @param int $code The error code (default: 0).
* @param Throwable|null $previous The previous throwable used for chaining exceptions (default: null).
*/
public function __construct(string $class, string $method, int $code = 0, ?Throwable $previous = null)
public function __construct(string $class, string $method, ?Throwable $previous = null)
{
parent::__construct("The method $method is not defined in class $class.", $code, $previous);
parent::__construct("The method $method is not defined in class $class.", $previous);
$this->code = 1508;
}
}
}
Loading

0 comments on commit 0be6ae3

Please sign in to comment.