Passed
Push — main ( 742327...639136 )
by Breno
13:44
created

DefinitionWrapper::isShareable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Habemus\Definition;
5
6
use Habemus\Definition\Build\ClassDefinition;
7
use Habemus\Definition\MethodCall\CallableMethod;
8
use Habemus\Definition\Sharing\Shareable;
9
use Habemus\Definition\Tag\Taggable;
10
use Habemus\Exception\DefinitionException;
11
12
final class DefinitionWrapper
13
{
14
    /**
15
     * @var Definition
16
     */
17
    protected $definition;
18
19
    public function __construct(Definition $definition)
20
    {
21
        $this->definition = $definition;
22
    }
23
24
    /**
25
     * @throws DefinitionException
26
     */
27
    public function constructor(string $param, $value): self
28
    {
29
        if ($this->definition instanceof ClassDefinition) {
30
            $this->definition->constructor($param, $value);
31
32
            return $this;
33
        }
34
35
        throw DefinitionException::unavailableConstructorParameters($this->definition);
36
    }
37
38
    /**
39
     * @throws DefinitionException
40
     */
41
    public function setShared(bool $share): self
42
    {
43
        if ($this->definition instanceof Shareable) {
44
            $this->definition->setShared($share);
45
46
            return $this;
47
        }
48
49
        throw DefinitionException::unshareable($this->definition);
50
    }
51
52
    public function isShared(): ?bool
53
    {
54
        if ($this->definition instanceof Shareable) {
55
            return $this->definition->isShared();
56
        }
57
58
        return null;
59
    }
60
61
    /**
62
     * @throws DefinitionException
63
     */
64
    public function addMethodCall(string $method, array $parameters = []): self
65
    {
66
        if ($this->definition instanceof CallableMethod) {
67
            $this->definition->addMethodCall($method, $parameters);
68
69
            return $this;
70
        }
71
72
        throw DefinitionException::unavailableMethodCall($this->definition);
73
    }
74
75
    /**
76
     * @throws DefinitionException
77
     */
78
    public function addTag(string ...$tag): self
79
    {
80
        if ($this->definition instanceof Taggable) {
81
            foreach ($tag as $_tag) {
82
                $this->definition->addTag($_tag);
83
            }
84
85
            return $this;
86
        }
87
88
        throw DefinitionException::untaggable($this->definition);
89
    }
90
}
91