-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom exceptions instead of using Runtimeexception everywhere
- Loading branch information
Sander De la Marche
committed
May 3, 2022
1 parent
4b51783
commit 3f35c43
Showing
10 changed files
with
147 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jug\Exception; | ||
|
||
use Exception; | ||
|
||
class ConfigException extends Exception | ||
{ | ||
public static function missingFile(): self | ||
{ | ||
return new self('Couldn\'t find a config.php file in your project.'); | ||
} | ||
|
||
public static function missingKey( | ||
string $key, | ||
): self { | ||
return new self(sprintf( | ||
'Missing required config key "%s".', | ||
$key | ||
)); | ||
} | ||
|
||
public static function missingPropertyTypeHint( | ||
string $propertyName, | ||
string $className, | ||
): self { | ||
return new self(sprintf( | ||
'Missing type hint for property "%s" on class "%s".', | ||
$propertyName, | ||
$className | ||
)); | ||
} | ||
|
||
public static function missingMethod( | ||
string $methodName, | ||
string $className, | ||
): self { | ||
return new self(sprintf( | ||
'Missing method "%s" on class "%s".', | ||
$methodName, | ||
$className | ||
)); | ||
} | ||
|
||
/** | ||
* @param array<string> $classes | ||
*/ | ||
public static function missingAttribute( | ||
string $attributeName, | ||
array $classes | ||
): self { | ||
return new self(sprintf( | ||
'Missing attribute "%s" on classes: "%s"', | ||
$attributeName, | ||
implode(',', $classes) | ||
)); | ||
} | ||
|
||
public static function nonExistentClass( | ||
string $className, | ||
): self { | ||
return new self(sprintf( | ||
'Class "%s" does not exist.', | ||
$className | ||
)); | ||
} | ||
|
||
public static function missingAbstractExtend( | ||
string $className, | ||
): self { | ||
return new self(sprintf( | ||
'Class "%s" does not extend the AbstractDataTransferObject class.', | ||
$className | ||
)); | ||
} | ||
|
||
public static function mappedClassMismatch( | ||
string $mappedClassName, | ||
string $passedClassname, | ||
): self { | ||
return new self(sprintf( | ||
'Passed object "%s" is not the same class as configured by the MapsTo attribute (%s)', | ||
$passedClassname, | ||
$mappedClassName | ||
)); | ||
} | ||
|
||
public static function updateWithoutSource(): self | ||
{ | ||
return new self('Running an update without passing a source entity is invalid.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jug\Exception; | ||
|
||
use Exception; | ||
|
||
class FileSystemException extends Exception | ||
{ | ||
public static function missingFile( | ||
string $fileName | ||
): self { | ||
return new self(sprintf( | ||
'Missing file: "%s".', | ||
$fileName | ||
)); | ||
} | ||
|
||
public static function missingDirectory( | ||
string $directoryName | ||
): self { | ||
return new self(sprintf( | ||
'Missing directory: %s', | ||
$directoryName, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters