Total Complexity | 7 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | abstract class Widget extends YiiWidget |
||
10 | { |
||
11 | private ?string $id = null; |
||
12 | private bool $autoGenerate = true; |
||
13 | private string $autoIdPrefix = 'w'; |
||
14 | private static int $counter = 0; |
||
15 | protected bool $darkTheme = false; |
||
16 | |||
17 | |||
18 | /** |
||
19 | * Returns the ID of the widget. |
||
20 | * |
||
21 | * $param string|null $suffix |
||
22 | * |
||
23 | * @return string|null ID of the widget. |
||
24 | */ |
||
25 | 173 | public function getId(?string $suffix = null): ?string |
|
26 | { |
||
27 | 173 | if ($this->autoGenerate && $this->id === null) { |
|
28 | 172 | $this->id = $this->autoIdPrefix . static::$counter++ . $suffix; |
|
|
|||
29 | } |
||
30 | |||
31 | 173 | return $this->id; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Set the ID of the widget. |
||
36 | * |
||
37 | * @return static |
||
38 | */ |
||
39 | 1 | public function id(string $value): static |
|
40 | { |
||
41 | 1 | $new = clone $this; |
|
42 | 1 | $new->id = $value; |
|
43 | |||
44 | 1 | return $new; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Counter used to generate {@see id} for widgets. |
||
49 | */ |
||
50 | 162 | public static function counter(int $value): void |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * The prefix to the automatically generated widget IDs. |
||
57 | * |
||
58 | * @return static |
||
59 | * {@see getId()} |
||
60 | */ |
||
61 | 1 | public function autoIdPrefix(string $value): static |
|
67 | } |
||
68 | |||
69 | 1 | public function withDarkTheme(bool $darkTheme = true): static |
|
77 |