unresolvablePropertyInjection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 10
c 1
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