1<?php
2
3namespace Doctrine\Instantiator\Exception;
4
5use InvalidArgumentException as BaseInvalidArgumentException;
6use ReflectionClass;
7
8use function interface_exists;
9use function sprintf;
10use function trait_exists;
11
12/**
13 * Exception for invalid arguments provided to the instantiator
14 */
15class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
16{
17    public static function fromNonExistingClass(string $className): self
18    {
19        if (interface_exists($className)) {
20            return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className));
21        }
22
23        if (trait_exists($className)) {
24            return new self(sprintf('The provided type "%s" is a trait, and can not be instantiated', $className));
25        }
26
27        return new self(sprintf('The provided class "%s" does not exist', $className));
28    }
29
30    /**
31     * @template T of object
32     * @phpstan-param ReflectionClass<T> $reflectionClass
33     */
34    public static function fromAbstractClass(ReflectionClass $reflectionClass): self
35    {
36        return new self(sprintf(
37            'The provided class "%s" is abstract, and can not be instantiated',
38            $reflectionClass->getName()
39        ));
40    }
41}
42