PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / vendor / wpfluent / framework / src / WPFluent / Support / InvalidArgumentException.php

InvalidArgumentException.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at vendor/wpfluent/framework/src/WPFluent/Support/InvalidArgumentException.php

56 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\Framework\Support;
4
5 use ReflectionClass;
6 use FluentBooking\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