| Total Complexity | 7 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class Hint extends Widget |
||
| 14 | { |
||
| 15 | use FormAttributeTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @psalm-var non-empty-string |
||
| 19 | */ |
||
| 20 | private string $tag = 'div'; |
||
| 21 | private array $tagAttributes = []; |
||
| 22 | |||
| 23 | private string|Stringable|null $content = null; |
||
| 24 | |||
| 25 | private bool $encode = true; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Set the container tag name for the hint. |
||
| 29 | * |
||
| 30 | * @param string $tag Container tag name. |
||
| 31 | * |
||
| 32 | * @return static |
||
| 33 | */ |
||
| 34 | 5 | public function tag(string $tag): self |
|
| 35 | { |
||
| 36 | 5 | if ($tag === '') { |
|
| 37 | 1 | throw new InvalidArgumentException('Tag name cannot be empty.'); |
|
| 38 | } |
||
| 39 | |||
| 40 | 4 | $new = clone $this; |
|
| 41 | 4 | $new->tag = $tag; |
|
| 42 | 4 | return $new; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return static |
||
| 47 | */ |
||
| 48 | 4 | public function tagAttributes(array $attributes): self |
|
| 49 | { |
||
| 50 | 4 | $new = clone $this; |
|
| 51 | 4 | $new->tagAttributes = $attributes; |
|
| 52 | 4 | return $new; |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return static |
||
| 57 | */ |
||
| 58 | 6 | public function content(string|Stringable|null $content): self |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Whether content should be HTML-encoded. |
||
| 67 | * |
||
| 68 | * @param bool $value |
||
| 69 | * |
||
| 70 | * @return static |
||
| 71 | */ |
||
| 72 | 2 | public function encode(bool $value): self |
|
| 73 | { |
||
| 74 | 2 | $new = clone $this; |
|
| 75 | 2 | $new->encode = $value; |
|
| 76 | 2 | return $new; |
|
| 77 | } |
||
| 78 | |||
| 79 | 41 | protected function run(): string |
|
| 88 | } |
||
| 89 | } |
||
| 90 |