Total Complexity | 5 |
Total Lines | 55 |
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; |
||
10 | private bool $autoGenerate = true; |
||
11 | private static int $counter = 0; |
||
12 | private static string $autoIdPrefix = 'w'; |
||
13 | |||
14 | /** |
||
15 | * Returns the Id of the widget. |
||
16 | * |
||
17 | * @return string Id of the widget. |
||
18 | */ |
||
19 | 132 | public function getId(): string |
|
20 | { |
||
21 | 132 | if ($this->autoGenerate) { |
|
22 | 132 | $this->id = self::$autoIdPrefix . static::$counter++; |
|
|
|||
23 | } |
||
24 | |||
25 | 132 | 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 setId(string $value): self |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Counter used to generate {@see id} for widgets. |
||
44 | * |
||
45 | * @param int $value |
||
46 | */ |
||
47 | 132 | public static function counter(int $value): void |
|
50 | 132 | } |
|
51 | |||
52 | /** |
||
53 | * The prefix to the automatically generated widget IDs. |
||
54 | * |
||
55 | * @param string $value |
||
56 | * |
||
57 | * {@see getId()} |
||
58 | */ |
||
59 | 1 | public static function autoIdPrefix(string $value): void |
|
64 |