summaryrefslogtreecommitdiff
path: root/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php')
-rw-r--r--vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php
new file mode 100644
index 000000000..33de31c0b
--- /dev/null
+++ b/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Exception/InvalidArgumentException.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Doctrine\Instantiator\Exception;
+
+use InvalidArgumentException as BaseInvalidArgumentException;
+use ReflectionClass;
+
+use function interface_exists;
+use function sprintf;
+use function trait_exists;
+
+/**
+ * Exception for invalid arguments provided to the instantiator
+ */
+class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
+{
+ public static function fromNonExistingClass(string $className): self
+ {
+ if (interface_exists($className)) {
+ return new self(sprintf('The provided type "%s" is an interface, and cannot be instantiated', $className));
+ }
+
+ if (trait_exists($className)) {
+ return new self(sprintf('The provided type "%s" is a trait, and cannot be instantiated', $className));
+ }
+
+ return new self(sprintf('The provided class "%s" does not exist', $className));
+ }
+
+ /**
+ * @phpstan-param ReflectionClass<T> $reflectionClass
+ *
+ * @template T of object
+ */
+ public static function fromAbstractClass(ReflectionClass $reflectionClass): self
+ {
+ return new self(sprintf(
+ 'The provided class "%s" is abstract, and cannot be instantiated',
+ $reflectionClass->getName()
+ ));
+ }
+
+ public static function fromEnum(string $className): self
+ {
+ return new self(sprintf(
+ 'The provided class "%s" is an enum, and cannot be instantiated',
+ $className
+ ));
+ }
+}