UseConst   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
c 0
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A asAttribute() 0 3 1
A __construct() 0 12 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