Test Setup Failed
Push — master ( 4c1de8...3a35d5 )
by Gabriel
02:10
created

HasAttributesTrait::getAttrib()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Nip\Form\Traits;
4
5
/**
6
 * Trait HasAttributesTrait
7
 * @package Nip\Form\Traits
8
 */
9
trait HasAttributesTrait
10
{
11
    protected $_attribs = [];
12
13
14
    /**
15
     * @param $key
16
     * @param $value
17
     * @return $this
18
     */
19 5
    public function setAttrib($key, $value)
20
    {
21 5
        $key = (string)$key;
22 5
        $this->_attribs[$key] = $value;
23
24 5
        return $this;
25
    }
26
27
    /**
28
     * @param string $key
29
     * @return string
30
     */
31 6 View Code Duplication
    public function getAttrib($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33 6
        $key = (string)$key;
34 6
        if (!isset($this->_attribs[$key])) {
35 6
            return null;
36
        }
37
38 5
        return $this->_attribs[$key];
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getAttribs()
45
    {
46
        return $this->_attribs;
47
    }
48
49
    /**
50
     * @param  array $attribs
51
     * @return $this
52
     */
53
    public function setAttribs(array $attribs)
54
    {
55
        $this->clearAttribs();
56
57
        return $this->addAttribs($attribs);
58
    }
59
60
    /**
61
     * @return $this
62
     */
63
    public function clearAttribs()
64
    {
65
        $this->_attribs = [];
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param  array $attribs
72
     * @return $this
73
     */
74
    public function addAttribs(array $attribs)
75
    {
76
        foreach ($attribs as $key => $value) {
77
            $this->setAttrib($key, $value);
78
        }
79
80
        return $this;
81
    }
82
83
    /**
84
     * @param $key
85
     * @return bool
86
     */
87 View Code Duplication
    public function removeAttrib($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        if (isset($this->_attribs[$key])) {
90
            unset($this->_attribs[$key]);
91
92
            return true;
93
        }
94
95
        return false;
96
    }
97
}
98