hanneskod /
readme-tester
| 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
|
|||
| 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 |
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.