PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.91
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.91
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Support / InvalidArgumentException.php

InvalidArgumentException.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.91, 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 FluentCommunity\Framework\Support;
4
5 use ReflectionClass;
6 use FluentCommunity\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