AbstractAttribute::createAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 18
rs 9.9332
cc 2
nc 2
nop 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