Exceptions > create instance of exception using static "create()" method (instead of constructor)

This commit is contained in:
Meritoo
2018-07-02 08:52:01 +02:00
parent 9342f0e87e
commit 834b24f348
35 changed files with 139 additions and 105 deletions

View File

@@ -19,12 +19,13 @@ use Exception;
class DisabledMethodException extends Exception
{
/**
* Class constructor
* Creates exception
*
* @param string $disabledMethod Name of the disabled method
* @param string $alternativeMethod (optional) Name of the alternative method
* @return DisabledMethodException
*/
public function __construct($disabledMethod, $alternativeMethod = '')
public static function create($disabledMethod, $alternativeMethod = '')
{
$template = 'Method %s() cannot be called, because is disabled.';
@@ -33,6 +34,7 @@ class DisabledMethodException extends Exception
}
$message = sprintf($template, $disabledMethod, $alternativeMethod);
parent::__construct($message);
return new static($message);
}
}