AbstractAttribute   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createAttribute() 0 18 2
A asAttribute() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Attribute;
6
7
abstract class AbstractAttribute implements AttributeInterface
8
{
9
    public function asAttribute(): string
10
    {
11
        return self::createAttribute();
12
    }
13
14
    public static function createAttribute(string ...$args): string
15
    {
16
        $arglist = '';
17
18
        if ($args) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $args of type array<integer,string> is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
19
            $arglist = sprintf(
20
                '("%s")',
21
                implode(
22
                    '", "',
23
                    array_map(
24
                        fn(string $arg) => addslashes(trim($arg)),
25
                        array_filter($args)
26
                    )
27
                )
28
            );
29
        }
30
31
        return '#[\\' . get_called_class() . $arglist . ']';
32
    }
33
}
34