InvalidArgumentException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNonExistingClass() 0 12 4
A fromAbstractClass() 0 7 1
1
<?php
2
3
namespace Doctrine\Instantiator\Exception;
4
5
use InvalidArgumentException as BaseInvalidArgumentException;
6
use ReflectionClass;
7
use const PHP_VERSION_ID;
8
use function interface_exists;
9
use function sprintf;
10
use function trait_exists;
11
12
/**
13
 * Exception for invalid arguments provided to the instantiator
14
 */
15
class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
16
{
17 3
    public static function fromNonExistingClass(string $className) : self
18
    {
19 3
        if (interface_exists($className)) {
20 1
            return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className));
21
        }
22
23 2
        if (PHP_VERSION_ID >= 50400 && trait_exists($className)) {
24 1
            return new self(sprintf('The provided type "%s" is a trait, and can not be instantiated', $className));
25
        }
26
27 1
        return new self(sprintf('The provided class "%s" does not exist', $className));
28
    }
29
30 1
    public static function fromAbstractClass(ReflectionClass $reflectionClass) : self
31
    {
32 1
        return new self(sprintf(
33 1
            'The provided class "%s" is abstract, and can not be instantiated',
34 1
            $reflectionClass->getName()
0 ignored issues
show
Bug introduced by
Consider using $reflectionClass->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
35
        ));
36
    }
37
}
38