FunctionModel   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 141
rs 10
c 0
b 0
f 0
wmc 15

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getParameters() 0 3 1
A isGlobal() 0 3 1
A getMockAnnotations() 0 4 1
A addParameter() 0 3 1
A getReturn() 0 3 1
A getAssertAnnotations() 0 4 1
A setIsGlobal() 0 3 1
A setReturn() 0 3 1
A getParamsAnnotation() 0 9 2
A getGetAnnotation() 0 9 2
A getSetAnnotation() 0 9 2
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use PhpUnitGen\Annotation\AnnotationInterface\AnnotationInterface;
17
use PhpUnitGen\Annotation\GetAnnotation;
18
use PhpUnitGen\Annotation\ParamsAnnotation;
19
use PhpUnitGen\Annotation\SetAnnotation;
20
use PhpUnitGen\Model\ModelInterface\FunctionModelInterface;
21
use PhpUnitGen\Model\ModelInterface\ParameterModelInterface;
22
use PhpUnitGen\Model\ModelInterface\ReturnModelInterface;
23
use PhpUnitGen\Model\PropertyTrait\AbstractTrait;
24
use PhpUnitGen\Model\PropertyTrait\DocumentationTrait;
25
use PhpUnitGen\Model\PropertyTrait\FinalTrait;
26
use PhpUnitGen\Model\PropertyTrait\NameTrait;
27
use PhpUnitGen\Model\PropertyTrait\NodeTrait;
28
use PhpUnitGen\Model\PropertyTrait\StaticTrait;
29
use PhpUnitGen\Model\PropertyTrait\VisibilityTrait;
30
31
/**
32
 * Class FunctionModel.
33
 *
34
 * @author     Paul Thébaud <[email protected]>.
35
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
36
 * @license    https://opensource.org/licenses/MIT The MIT license.
37
 * @link       https://github.com/paul-thebaud/phpunit-generator
38
 * @since      Class available since Release 2.0.0.
39
 */
40
class FunctionModel implements FunctionModelInterface
41
{
42
    use NameTrait;
43
    use VisibilityTrait;
44
    use StaticTrait;
45
    use FinalTrait;
46
    use AbstractTrait;
47
    use NodeTrait;
48
    use DocumentationTrait;
49
50
    /**
51
     * @var ParameterModelInterface[]|Collection $parameters The function methods.
52
     */
53
    private $parameters;
54
55
    /**
56
     * @var ReturnModelInterface $return The function return.
57
     */
58
    private $return;
59
60
    /**
61
     * @var bool $isGlobal Tells if the function is global.
62
     */
63
    private $isGlobal = false;
64
65
    /**
66
     * FunctionModel constructor.
67
     */
68
    public function __construct()
69
    {
70
        $this->parameters  = new ArrayCollection();
71
        $this->annotations = new ArrayCollection();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function addParameter(ParameterModelInterface $parameter): void
78
    {
79
        $this->parameters->add($parameter);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getParameters(): Collection
86
    {
87
        return $this->parameters;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function setReturn(ReturnModelInterface $return): void
94
    {
95
        $this->return = $return;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getReturn(): ReturnModelInterface
102
    {
103
        return $this->return;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function setIsGlobal(bool $isGlobal): void
110
    {
111
        $this->isGlobal = $isGlobal;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function isGlobal(): bool
118
    {
119
        return $this->isGlobal;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function getParamsAnnotation(): ?ParamsAnnotation
126
    {
127
        $annotations = $this->annotations->filter(function (AnnotationInterface $annotation) {
128
            return $annotation->getType() === AnnotationInterface::TYPE_PARAMS;
129
        });
130
        if ($annotations->isEmpty()) {
131
            return null;
132
        }
133
        return $annotations->first();
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function getGetAnnotation(): ?GetAnnotation
140
    {
141
        $annotations = $this->annotations->filter(function (AnnotationInterface $annotation) {
142
            return $annotation->getType() === AnnotationInterface::TYPE_GET;
143
        });
144
        if ($annotations->isEmpty()) {
145
            return null;
146
        }
147
        return $annotations->first();
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153
    public function getSetAnnotation(): ?SetAnnotation
154
    {
155
        $annotations = $this->annotations->filter(function (AnnotationInterface $annotation) {
156
            return $annotation->getType() === AnnotationInterface::TYPE_SET;
157
        });
158
        if ($annotations->isEmpty()) {
159
            return null;
160
        }
161
        return $annotations->first();
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167
    public function getAssertAnnotations(): Collection
168
    {
169
        return $this->annotations->filter(function (AnnotationInterface $annotation) {
170
            return $annotation->getType() === AnnotationInterface::TYPE_ASSERT;
171
        });
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177
    public function getMockAnnotations(): Collection
178
    {
179
        return $this->annotations->filter(function (AnnotationInterface $annotation) {
180
            return $annotation->getType() === AnnotationInterface::TYPE_MOCK;
181
        });
182
    }
183
}
184