| Total Complexity | 4 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | trait AttributedTrait |
||
| 11 | { |
||
| 12 | /** @var array<non-empty-string, mixed> */ |
||
|
|
|||
| 13 | private array $attributes = []; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @return array<non-empty-string, mixed> Attributes derived from the context. |
||
| 17 | */ |
||
| 18 | public function getAttributes(): array |
||
| 19 | { |
||
| 20 | return $this->attributes; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param non-empty-string $name |
||
| 25 | */ |
||
| 26 | public function getAttribute(string $name, mixed $default = null): mixed |
||
| 27 | { |
||
| 28 | return $this->attributes[$name] ?? $default; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param non-empty-string $name |
||
| 33 | */ |
||
| 34 | public function withAttribute(string $name, mixed $value): static |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param non-empty-string $name |
||
| 43 | */ |
||
| 44 | public function withoutAttribute(string $name): static |
||
| 49 | } |
||
| 50 | } |
||
| 51 |