fluent-boards
/
vendor
/
wpfluent
/
framework
/
src
/
WPFluent
/
Support
/
InvalidArgumentException.php
InvalidArgumentException.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.31, at vendor/wpfluent/framework/src/WPFluent/Support/InvalidArgumentException.php
| 1 | <?php |
| 2 | |
| 3 | namespace FluentBoards\Framework\Support; |
| 4 | |
| 5 | use ReflectionClass; |
| 6 | use FluentBoards\Framework\Support\ExceptionInterface; |
| 7 | use InvalidArgumentException as BaseInvalidArgumentException; |
| 8 | |
| 9 | use function sprintf; |
| 10 | use function trait_exists; |
| 11 | use function interface_exists; |
| 12 | |
| 13 | /** |
| 14 | * Exception for invalid arguments provided to the instantiator |
| 15 | */ |
| 16 | class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface |
| 17 | { |
| 18 | public static function fromNonExistingClass(string $className): self |
| 19 | { |
| 20 | if (interface_exists($className)) { |
| 21 | return new self( |
| 22 | sprintf('The provided type "%s" is an interface, and cannot be instantiated', $className) |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | if (trait_exists($className)) { |
| 27 | return new self( |
| 28 | sprintf('The provided type "%s" is a trait, and cannot be instantiated', $className) |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | return new self(sprintf('The provided class "%s" does not exist', $className)); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @phpstan-param ReflectionClass<T> $reflectionClass |
| 37 | * |
| 38 | * @template T of object |
| 39 | */ |
| 40 | public static function fromAbstractClass(ReflectionClass $reflectionClass): self |
| 41 | { |
| 42 | return new self(sprintf( |
| 43 | 'The provided class "%s" is abstract, and cannot be instantiated', |
| 44 | $reflectionClass->getName() |
| 45 | )); |
| 46 | } |
| 47 | |
| 48 | public static function fromEnum(string $className): self |
| 49 | { |
| 50 | return new self(sprintf( |
| 51 | 'The provided class "%s" is an enum, and cannot be instantiated', |
| 52 | $className |
| 53 | )); |
| 54 | } |
| 55 | } |
| 56 |