InjectionException::invalidInjection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Exception;
5
6
use ReflectionParameter;
7
use ReflectionProperty;
8
9
class InjectionException extends ContainerException
10
{
11
12
    public static function notAnObject($value)
13
    {
14
        return new self(
15
            sprintf(
16
                "Expected object to inject property dependencies. Got (%s).",
17
                gettype($value)
18
            )
19
        );
20
    }
21
22
    public static function unresolvablePropertyInjection(ReflectionProperty $property, $object): self
23
    {
24
        return new self(
25
            sprintf(
26
                "Cannot resolve the injection for property ($%s) in (%s).",
27
                $property->getName(),
28
                get_class($object)
29
            )
30
        );
31
    }
32
33
    /**
34
     * @param ReflectionProperty|ReflectionParameter $propertyOrParameter
35
     * @return self
36
     */
37
    public static function invalidInjection($propertyOrParameter): self
38
    {
39
        $type = $propertyOrParameter instanceof ReflectionProperty ? "property" : "constructor parameter";
40
        return new self(
41
            sprintf(
42
                "Impossible to determine the injection for %s ($%s) in (%s).",
43
                $type,
44
                $propertyOrParameter->getName(),
45
                $propertyOrParameter->getDeclaringClass()->getName()
46
            )
47
        );
48
    }
49
}
50