ViewTag::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace andmemasin\helpers;
3
4
use yii\helpers\Html;
5
6
/**
7
 * Class ViewTag
8
 * Generates an invisible HTML Tag that is meant for identifying page machine-readable (eg automated tests)
9
 * @package andmemasin\helpers
10
 * @author Tõnis Ormisson <[email protected]>
11
 */
12
class ViewTag
13
{
14
    /** @var string $name */
15
    private $name;
16
    const PREFIX = "action";
17
    const DELIMITER = "::";
18
19
    /**
20
     * ViewTag constructor.
21
     * @param string $name
22
     */
23
    public function __construct(string $name)
24
    {
25
        $this->name = $name;
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getId()
32
    {
33
        return self::PREFIX . self::DELIMITER . Html::encode($this->name);
34
    }
35
36
    public function __toString()
37
    {
38
        return Html::tag("x-test", null, ['id' => $this->getId()]);
39
    }
40
41
42
}