DefinitionException::unshareable()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Exception;
5
6
use Habemus\Definition\Definition;
7
8
class DefinitionException extends ContainerException
9
{
10
    /**
11
     * @var Definition
12
     */
13
    protected $definition;
14
15
    public function __construct(Definition $definition, $message = "", $code = 0, $previous = null)
16
    {
17
        $this->definition = $definition;
18
        parent::__construct($message, $code, $previous);
19
    }
20
21
    public function getDefinition(): Definition
22
    {
23
        return $this->definition;
24
    }
25
26
    public static function invalidMethodCall(Definition $definition, $instance, $method): self
27
    {
28
        return new self(
29
            $definition,
30
            sprintf(
31
                "The definition of %s (%s) cannot to call the method (%s::%s).",
32
                $definition->getIdentity() ? "id" : "type",
33
                $definition->getIdentity() ?? get_class($definition),
34
                is_object($instance) ? get_class($instance) : gettype($instance),
35
                $method
36
            )
37
        );
38
    }
39
40
    public static function unavailableConstructorParameters(Definition $definition): self
41
    {
42
        return new self(
43
            $definition,
44
            sprintf(
45
                "The definition of %s (%s) does not accept constructor parameters.",
46
                $definition->getIdentity() ? "id" : "type",
47
                $definition->getIdentity() ?? get_class($definition)
48
            )
49
        );
50
    }
51
52
    public static function unavailableMethodCall(Definition $definition): self
53
    {
54
        return new self(
55
            $definition,
56
            sprintf(
57
                "The definition of %s (%s) does not accept method calls.",
58
                $definition->getIdentity() ? "id" : "type",
59
                $definition->getIdentity() ?? get_class($definition)
60
            )
61
        );
62
    }
63
64
    public static function unshareable(Definition $definition): self
65
    {
66
        return new self(
67
            $definition,
68
            sprintf(
69
                "The definition of %s (%s) is not shareable.",
70
                $definition->getIdentity() ? "id" : "type",
71
                $definition->getIdentity() ?? get_class($definition)
72
            )
73
        );
74
    }
75
76
    public static function untaggable(Definition $definition): self
77
    {
78
        return new self(
79
            $definition,
80
            sprintf(
81
                "The definition of %s (%s) is not taggable.",
82
                $definition->getIdentity() ? "id" : "type",
83
                $definition->getIdentity() ?? get_class($definition)
84
            )
85
        );
86
    }
87
}
88