| Total Complexity | 10 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class AttributesRenderer |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var AttributeCollection |
||
| 13 | */ |
||
| 14 | private $collection; |
||
| 15 | |||
| 16 | public function __construct(AttributeCollection $collection) |
||
| 17 | { |
||
| 18 | $this->collection = $collection; |
||
| 19 | } |
||
| 20 | |||
| 21 | public function render() : string |
||
| 22 | { |
||
| 23 | $list = array(); |
||
| 24 | |||
| 25 | $attributes = $this->compileAttributes(); |
||
| 26 | |||
| 27 | if(empty($attributes)) |
||
| 28 | { |
||
| 29 | return ''; |
||
| 30 | } |
||
| 31 | |||
| 32 | foreach($attributes as $name => $value) |
||
| 33 | { |
||
| 34 | if($value === '') |
||
| 35 | { |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | |||
| 39 | $list[] = $this->renderAttribute($name, $value); |
||
| 40 | } |
||
| 41 | |||
| 42 | return ' '.implode(' ', $list); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Compiles all attributes, including the dynamic ones, |
||
| 47 | * into an associative array with attribute name => value |
||
| 48 | * pairs. |
||
| 49 | * |
||
| 50 | * @return array<string,string> |
||
| 51 | */ |
||
| 52 | public function compileAttributes() : array |
||
| 69 | } |
||
| 70 | |||
| 71 | private function renderAttribute(string $name, string $value) : string |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | } |
||
| 85 |