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

@@ -41,7 +41,7 @@ class Bundle
* Given name of bundle is invalid?
*/
if (!Regex::isValidBundleName($bundleName)) {
throw new IncorrectBundleNameException($bundleName);
throw IncorrectBundleNameException::create($bundleName);
}
/*

View File

@@ -11,7 +11,7 @@ namespace Meritoo\Common\Utilities;
use DateInterval;
use DateTime;
use Exception;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Exception\Type\UnknownDatePartTypeException;
use Meritoo\Common\Type\DatePartType;
use Meritoo\Common\Type\DatePeriod;
@@ -255,21 +255,21 @@ class Date
* Oops, incorrect year
*/
if ($year <= 0) {
throw new UnknownDatePartTypeException(DatePartType::YEAR, $year);
throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year);
}
/*
* Oops, incorrect month
*/
if ($month < 1 || $month > 12) {
throw new UnknownDatePartTypeException(DatePartType::MONTH, $month);
throw UnknownDatePartTypeException::createException(DatePartType::MONTH, $month);
}
/*
* Oops, incorrect day
*/
if ($day < 1 || $day > 31) {
throw new UnknownDatePartTypeException(DatePartType::DAY, $day);
throw UnknownDatePartTypeException::createException(DatePartType::DAY, $day);
}
if ($month < 3) {

View File

@@ -524,7 +524,7 @@ class Reflection
* Oops, cannot resolve class
*/
if (null === $className) {
throw new CannotResolveClassNameException($class);
throw CannotResolveClassNameException::create($class);
}
$childClasses = [];
@@ -558,7 +558,6 @@ class Reflection
*
* @param array|object|string $parentClass Class who child class should be returned. An array of objects,
* namespaces, object or namespace.
* @throws CannotResolveClassNameException
* @throws MissingChildClassesException
* @throws TooManyChildClassesException
* @return mixed
@@ -572,7 +571,7 @@ class Reflection
* Oops, the base / parent class hasn't child class
*/
if (empty($childClasses)) {
throw new MissingChildClassesException($parentClass);
throw MissingChildClassesException::create($parentClass);
}
/*
@@ -580,7 +579,7 @@ class Reflection
* Oops, the base / parent class has too many child classes
*/
if (count($childClasses) > 1) {
throw new TooManyChildClassesException($parentClass, $childClasses);
throw TooManyChildClassesException::create($parentClass, $childClasses);
}
return trim($childClasses[0]);
@@ -621,7 +620,6 @@ class Reflection
* @param bool $verifyParents If is set to true, parent classes are verified if they use given
* trait. Otherwise - not.
* @throws CannotResolveClassNameException
* @throws ReflectionException
* @return bool|null
*/
public static function usesTrait($class, $trait, $verifyParents = false)
@@ -633,7 +631,7 @@ class Reflection
* Oops, cannot resolve class
*/
if (empty($className)) {
throw new CannotResolveClassNameException($class);
throw CannotResolveClassNameException::create($class);
}
/*