Widget   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 57
ccs 10
cts 12
cp 0.8333
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A autoIdPrefix() 0 3 1
A counter() 0 3 1
A setId() 0 5 1
A getId() 0 7 2
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
Bug introduced by
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