Completed
Push — master ( d10f54...00ced4 )
by
unknown
05:32
created

MethodDefinition   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 97
rs 10
c 0
b 0
f 0
ccs 24
cts 24
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A defineParameter() 0 13 2
A getMethodName() 0 4 1
A isPublic() 0 4 1
A setIsPublic() 0 6 1
A setMethodName() 0 6 1
A getModifiers() 0 4 1
A setModifiers() 0 6 1
A getParametersCollection() 0 4 1
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 02.08.16
6
 * Time: 0:46.
7
 */
8
namespace samsonframework\container\definition;
9
10
use samsonframework\container\definition\exception\ParameterDefinitionAlreadyExistsException;
11
use samsonframework\container\definition\exception\ParameterNotFoundException;
12
13
/**
14
 * Class MethodDefinition
15
 *
16
 * @package samsonframework\container\definition
17
 */
18
class MethodDefinition extends AbstractDefinition implements MethodBuilderInterface
19
{
20
    /** @var  string Method name */
21
    protected $methodName;
22
    /** @var ParameterDefinition[] Collection of parameter collection */
23
    protected $parametersCollection = [];
24
    /** @var int Method modifiers */
25
    protected $modifiers = 0;
26
    /** @var bool Flag that method is public */
27
    protected $isPublic = false;
28
29
    /**
30
     * Define arguments
31
     *
32
     * @param string $parameterName
33
     * @return ParameterBuilderInterface
34
     * @throws ParameterDefinitionAlreadyExistsException
35
     */
36 13
    public function defineParameter($parameterName): ParameterBuilderInterface
37
    {
38 13
        if (array_key_exists($parameterName, $this->parametersCollection)) {
39 1
            throw new ParameterDefinitionAlreadyExistsException();
40
        }
41
42 13
        $parameter = new ParameterDefinition($this);
43 13
        $parameter->setParameterName($parameterName);
44
45 13
        $this->parametersCollection[$parameterName] = $parameter;
46
47 13
        return $parameter;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 2
    public function getMethodName(): string
54
    {
55 2
        return $this->methodName;
56
    }
57
58
    /**
59
     * @return boolean
60
     */
61 3
    public function isPublic(): bool
62
    {
63 3
        return $this->isPublic;
64
    }
65
66
    /**
67
     * @param boolean $isPublic
68
     * @return MethodDefinition
69
     */
70 6
    public function setIsPublic(bool $isPublic): MethodDefinition
71
    {
72 6
        $this->isPublic = $isPublic;
73
74 6
        return $this;
75
    }
76
77
    /**
78
     * @param string $methodName
79
     * @return MethodDefinition
80
     */
81 16
    public function setMethodName(string $methodName): MethodDefinition
82
    {
83 16
        $this->methodName = $methodName;
84
85 16
        return $this;
86
    }
87
88
    /**
89
     * @return int
90
     */
91 1
    public function getModifiers(): int
92
    {
93 1
        return $this->modifiers;
94
    }
95
96
    /**
97
     * @param int $modifiers
98
     * @return MethodDefinition
99
     */
100 6
    public function setModifiers(int $modifiers): MethodDefinition
101
    {
102 6
        $this->modifiers = $modifiers;
103
104 6
        return $this;
105
    }
106
107
    /**
108
     * @return ParameterDefinition[]
109
     */
110 8
    public function getParametersCollection(): array
111
    {
112 8
        return $this->parametersCollection;
113
    }
114
}
115