Issues (13)

src/Widget.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Bootstrap4;
6
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++;
0 ignored issues
show
Since $counter is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $counter to at least protected.
Loading history...
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
62
    {
63
        self::$autoIdPrefix = $value;
64
    }
65
}
66