Total Complexity | 6 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract class Widget extends \Yiisoft\Widget\Widget |
||
8 | { |
||
9 | private ?string $id = null; |
||
10 | private bool $autoGenerate = true; |
||
11 | private string $autoIdPrefix = 'w'; |
||
12 | private static int $counter = 0; |
||
13 | |||
14 | /** |
||
15 | * Returns the Id of the widget. |
||
16 | * |
||
17 | * @return string|null Id of the widget. |
||
18 | */ |
||
19 | 134 | protected function getId(): ?string |
|
20 | { |
||
21 | 134 | if ($this->autoGenerate && $this->id === null) { |
|
22 | 133 | $this->id = $this->autoIdPrefix . static::$counter++; |
|
|
|||
23 | } |
||
24 | |||
25 | 134 | return $this->id; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * Set the Id of the widget. |
||
30 | * |
||
31 | * @param string $value |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | 1 | public function withId(string $value): self |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Counter used to generate {@see id} for widgets. |
||
45 | * |
||
46 | * @param int $value |
||
47 | */ |
||
48 | 124 | public static function counter(int $value): void |
|
49 | { |
||
50 | 124 | self::$counter = $value; |
|
51 | 124 | } |
|
52 | |||
53 | /** |
||
54 | * The prefix to the automatically generated widget IDs. |
||
55 | * |
||
56 | * @param string $value |
||
57 | * |
||
58 | * @return $this |
||
59 | * |
||
60 | * {@see getId()} |
||
61 | */ |
||
62 | 1 | public function withAutoIdPrefix(string $value): self |
|
68 | } |
||
69 | } |
||
70 |