| Total Complexity | 10 |
| Total Lines | 87 |
| Duplicated Lines | 0 % |
| Coverage | 57.69% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | trait HasAttributesTrait |
||
| 10 | { |
||
| 11 | protected $_attribs = []; |
||
| 12 | |||
| 13 | |||
| 14 | /** |
||
| 15 | * @param $key |
||
| 16 | * @param $value |
||
| 17 | * @return $this |
||
| 18 | */ |
||
| 19 | 7 | public function setAttrib($key, $value) |
|
| 20 | { |
||
| 21 | 7 | $key = (string)$key; |
|
| 22 | 7 | $this->_attribs[$key] = $value; |
|
| 23 | |||
| 24 | 7 | return $this; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $key |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 9 | public function getAttrib($key) |
|
| 32 | { |
||
| 33 | 9 | $key = (string)$key; |
|
| 34 | 9 | if (!isset($this->_attribs[$key])) { |
|
| 35 | 9 | return null; |
|
| 36 | } |
||
| 37 | |||
| 38 | 6 | return $this->_attribs[$key]; |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | 1 | public function getAttribs() |
|
| 45 | { |
||
| 46 | 1 | 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 | 1 | public function addAttribs(array $attribs) |
|
| 75 | { |
||
| 76 | 1 | foreach ($attribs as $key => $value) { |
|
| 77 | 1 | $this->setAttrib($key, $value); |
|
| 78 | } |
||
| 79 | |||
| 80 | 1 | return $this; |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param $key |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | public function removeAttrib($key) |
||
| 96 | } |
||
| 97 | } |
||
| 98 |