HasDataTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 44
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureData() 0 6 2
A getData() 0 9 2
A setData() 0 7 1
1
<?php
2
namespace Sirius\Input\Traits;
3
4
use Sirius\Input\Specs;
5
use Sirius\Input\DataContainer;
6
7
trait HasDataTrait
8
{
9
10 2
    protected function ensureData()
11
    {
12 2
        if (!isset($this[Specs::DATA])) {
13 2
            $this[Specs::DATA] = new DataContainer();
14 2
        }
15 2
    }
16
17
    /**
18
     * Retrieve an attribute from the label
19
     *
20
     * @param string $key
21
     *
22
     * @return mixed
23
     */
24 2
    public function getData($key = null)
25
    {
26 2
        $this->ensureData();
27 2
        if ($key === null) {
28 1
            return $this[Specs::DATA]->getAll();
29
        }
30
31 2
        return $this[Specs::DATA]->get($key);
32
    }
33
34
    /**
35
     * Set/Unset a label attribute
36
     *
37
     * @param string $keyOrArray
38
     * @param mixed|null $value
39
     *
40
     * @return self
41
     */
42 2
    public function setData($keyOrArray, $value = null)
43
    {
44 2
        $this->ensureData();
45 2
        $this[Specs::DATA]->set($keyOrArray, $value);
46
47 2
        return $this;
48
    }
49
50
}