| Total Complexity | 6 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 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 | * $param string|null $suffix |
||
| 18 | * |
||
| 19 | * @return string|null Id of the widget. |
||
| 20 | */ |
||
| 21 | 167 | public function getId(?string $suffix = null): ?string |
|
| 22 | { |
||
| 23 | 167 | if ($this->autoGenerate && $this->id === null) { |
|
| 24 | 166 | $this->id = $this->autoIdPrefix . static::$counter++ . $suffix; |
|
|
|
|||
| 25 | } |
||
| 26 | |||
| 27 | 167 | return $this->id; |
|
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Set the Id of the widget. |
||
| 32 | * |
||
| 33 | * @param string $value |
||
| 34 | * |
||
| 35 | * @return self |
||
| 36 | */ |
||
| 37 | 1 | public function id(string $value): self |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Counter used to generate {@see id} for widgets. |
||
| 47 | * |
||
| 48 | * @param int $value |
||
| 49 | */ |
||
| 50 | 156 | public static function counter(int $value): void |
|
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The prefix to the automatically generated widget IDs. |
||
| 57 | * |
||
| 58 | * @param string $value |
||
| 59 | * |
||
| 60 | * @return self |
||
| 61 | * |
||
| 62 | * {@see getId()} |
||
| 63 | */ |
||
| 64 | 1 | public function autoIdPrefix(string $value): self |
|
| 72 |