AttributeAwareTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 65
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 4 1
A getAttribute() 0 4 1
A removeAttribute() 0 4 1
A hasAttribute() 0 4 1
A getAttributes() 0 4 1
A clearAttributes() 0 4 1
A hasAttributes() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the bisarca/graph package.
5
 *
6
 * (c) Emanuele Minotto <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bisarca\Graph\Attribute;
13
14
/**
15
 * Trait to facilitate attributes implementation.
16
 */
17
trait AttributeAwareTrait
18
{
19
    /**
20
     * Contained attributes.
21
     *
22
     * @var array
23
     */
24
    private $attributes = [];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function setAttribute(string $name, $value)
30
    {
31
        $this->attributes[$name] = $value;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getAttribute(string $name, $default = null)
38
    {
39
        return $this->attributes[$name] ?? $default;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function removeAttribute(string $name)
46
    {
47
        unset($this->attributes[$name]);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function hasAttribute(string $name): bool
54
    {
55
        return isset($this->attributes[$name]);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getAttributes(): array
62
    {
63
        return $this->attributes;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function clearAttributes()
70
    {
71
        $this->attributes = [];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function hasAttributes(): bool
78
    {
79
        return !empty($this->attributes);
80
    }
81
}
82