1<?php
2
3namespace Doctrine\Instantiator\Exception;
4
5use InvalidArgumentException as BaseInvalidArgumentException;
6use ReflectionClass;
7use const PHP_VERSION_ID;
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 (PHP_VERSION_ID >= 50400 && 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    public static function fromAbstractClass(ReflectionClass $reflectionClass) : self
31    {
32        return new self(sprintf(
33            'The provided class "%s" is abstract, and can not be instantiated',
34            $reflectionClass->getName()
35        ));
36    }
37}
38