Passed
Push — master ( 3d4557...4c2a8d )
by Hannes
01:54
created

UseConst::__construct()   A

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
// phpcs:disable PSR1.Files.SideEffects
4
5
declare(strict_types=1);
6
7
namespace hanneskod\readmetester\Attribute;
8
9
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_ALL)]
10
class UseConst extends PrependCode
11
{
12
    private string $constname;
13
    private string $as = '';
14
15
    public function __construct(string $constname, string $as = '')
16
    {
17
        $code = "use const $constname";
18
19
        if ($as) {
20
            $code .= " as $as";
21
        }
22
23
        parent::__construct("$code;");
24
25
        $this->constname = $constname;
26
        $this->as = $as;
27
    }
28
29
    public function asAttribute(): string
30
    {
31
        return self::createAttribute($this->constname, $this->as);
32
    }
33
}
34