UseConst::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Attribute;
6
7
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
8
class UseConst extends PrependCode
9
{
10
    private string $constname;
11
    private string $as = '';
12
13
    public function __construct(string $constname, string $as = '')
14
    {
15
        $code = "use const $constname";
16
17
        if ($as) {
18
            $code .= " as $as";
19
        }
20
21
        parent::__construct("$code;");
22
23
        $this->constname = $constname;
24
        $this->as = $as;
25
    }
26
27
    public function asAttribute(): string
28
    {
29
        return self::createAttribute($this->constname, $this->as);
30
    }
31
}
32