Passed
Push — develop ( 45600c...ff69f6 )
by Paul
03:16
created

TraitModel::addAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace PhpUnitGen\Model;
4
5
use PhpUnitGen\Model\ModelInterface\AttributeModelInterface;
6
use PhpUnitGen\Model\ModelInterface\TraitModelInterface;
7
8
/**
9
 * Class TraitModel.
10
 *
11
 * @author     Paul Thébaud <[email protected]>.
12
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
13
 * @license    https://opensource.org/licenses/MIT The MIT license.
14
 * @link       https://github.com/paul-thebaud/phpunit-generator
15
 * @since      Class available since Release 2.0.0.
16
 */
17
class TraitModel extends InterfaceModel implements TraitModelInterface
18
{
19
    /**
20
     * @var AttributeModel[] $attributes Class attributes.
21
     */
22
    private $attributes = [];
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function addAttribute(AttributeModelInterface $attribute): void
28
    {
29
        $this->attributes[] = $attribute;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function hasAttribute(string $name): bool
36
    {
37
        foreach ($this->attributes as $attribute) {
38
            if ($attribute->getName() === $name) {
39
                return true;
40
            }
41
        }
42
        return false;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getAttribute(string $name): ?AttributeModelInterface
49
    {
50
        foreach ($this->attributes as $attribute) {
51
            if ($attribute->getName() === $name) {
52
                return $attribute;
53
            }
54
        }
55
        return null;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getAttributes(): array
62
    {
63
        return $this->attributes;
64
    }
65
}