| Total Complexity | 7 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | trait RenderableTrait |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var array |
||
| 15 | */ |
||
| 16 | private $attributes = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * {@inheritdoc} |
||
| 20 | */ |
||
| 21 | 28 | public function __call(string $name, array $arguments) |
|
| 22 | { |
||
| 23 | 28 | if (empty($arguments)) { |
|
| 24 | 2 | throw new ArgumentCountError('Missing the attribute value.'); |
|
| 25 | } |
||
| 26 | |||
| 27 | 26 | return $this->set($name, $arguments[0]); |
|
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | 28 | public function set(string $name, $value) |
|
| 34 | { |
||
| 35 | 28 | if (!is_scalar($value)) { |
|
| 36 | 2 | throw new TypeError('The attribute value must be a scalar value.'); |
|
| 37 | } |
||
| 38 | |||
| 39 | 26 | $this->attributes[$name] = $value; |
|
| 40 | |||
| 41 | 26 | return $this; |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | 4 | public function unset(string $name) |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | 9 | public function attributes(): array |
|
| 58 | { |
||
| 59 | 9 | return $this->attributes; |
|
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | abstract public function render(): string; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | 36 | public function __toString(): string |
|
| 73 | } |
||
| 74 | } |
||
| 75 |