Passed
Pull Request — master (#35)
by Wilmer
02:09
created

Widget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 55
ccs 12
cts 12
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setId() 0 5 1
A getId() 0 7 2
A counter() 0 3 1
A autoIdPrefix() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Bootstrap5;
6
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++;
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...
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
36
    {
37 1
        $this->id = $value;
38
39 1
        return $this;
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
48
    {
49 132
        self::$counter = $value;
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
60
    {
61 1
        self::$autoIdPrefix = $value;
62 1
    }
63
}
64