Total Complexity | 9 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Coverage | 96% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | trait HasAttribsTrait |
||
12 | { |
||
13 | /** |
||
14 | * @param array $overrides |
||
15 | * @return string |
||
16 | */ |
||
17 | 1 | public function renderAttributes($overrides = []) |
|
18 | { |
||
19 | 1 | $attribs = $this->getElement()->getAttribs(); |
|
|
|||
20 | 1 | if (!isset($attribs['title'])) { |
|
21 | 1 | $attribs['title'] = $this->getElement()->getLabel(); |
|
22 | } |
||
23 | 1 | $allowedAttribs = $this->getAllowedAttributes(); |
|
24 | 1 | $attribs = array_filter( |
|
25 | 1 | $attribs, |
|
26 | function ($key) use ($allowedAttribs) { |
||
27 | 1 | return $this->canRenderAttribute($key, $allowedAttribs); |
|
28 | 1 | }, |
|
29 | 1 | ARRAY_FILTER_USE_KEY |
|
30 | ); |
||
31 | 1 | $return = ''; |
|
32 | 1 | foreach ($attribs as $name => $value) { |
|
33 | 1 | if (in_array($name, array_keys($overrides))) { |
|
34 | $value = $overrides[$name]; |
||
35 | } |
||
36 | |||
37 | 1 | $return .= ' ' . $name . '="' . $value . '"'; |
|
38 | } |
||
39 | |||
40 | 1 | return $return; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return array |
||
45 | */ |
||
46 | 1 | public function getAllowedAttributes() |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param $name |
||
53 | * @param null $allowed |
||
54 | * @return bool |
||
55 | */ |
||
56 | 1 | protected function canRenderAttribute($name, $allowed = null) |
|
68 |