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