Completed
Push — develop ( 1b34c6...481302 )
by Paul
02:47
created

TraitModel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 47
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 3 1
A hasAttribute() 0 8 3
A getAttribute() 0 8 3
A addAttribute() 0 3 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 AttributeModelInterface[] $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
}
66