Passed
Push — master ( 80ddec...cae974 )
by Caen
03:33 queued 12s
created

LinkItem::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Hyde\Framework\Models\Metadata;
4
5
use Hyde\Framework\Contracts\MetadataItemContract;
6
7
class LinkItem implements MetadataItemContract, \Stringable
8
{
9
    public function __construct(protected string $rel, protected string $href, protected array $attr = [])
10
    {
11
    }
12
13
    public function __toString(): string
14
    {
15
        if (! $this->attr) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->attr of type array 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...
16
            return '<link rel="'.e($this->rel).'" href="'.e($this->href).'">';
17
        }
18
19
        $attributes = collect($this->attr)->map(function ($value, $key) {
0 ignored issues
show
Bug introduced by
$this->attr of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        $attributes = collect(/** @scrutinizer ignore-type */ $this->attr)->map(function ($value, $key) {
Loading history...
20
            return e($key).'="'.e($value).'"';
21
        })->implode(' ');
22
23
        return '<link rel="'.e($this->rel).'" href="'.e($this->href).'" '.$attributes.'>';
24
    }
25
26
    public function uniqueKey(): string
27
    {
28
        return $this->rel;
29
    }
30
}
31