Passed
Pull Request — main (#17)
by
unknown
01:51
created

Extension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A attrs() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Node\Inline;
6
7
use DH\Adf\Node\InlineNode;
8
9
class Extension extends InlineNode
10
{
11
    protected string $type = 'extension';
12
    private string $layout;
13
    private string $extensionType;
14
    private string $extensionKey;
15
    private array $parameters;
16
    private string $localId;
17
18
    public function __construct(
19
        string $layout,
20
        string $extensionType,
21
        string $extensionKey,
22
        array $parameters,
23
        string $localId
24
    ) {
25
        $this->layout = $layout;
26
        $this->extensionType = $extensionType;
27
        $this->extensionKey = $extensionKey;
28
        $this->parameters = $parameters;
29
        $this->localId = $localId;
30
    }
31
32
    protected function attrs(): array
33
    {
34
        $attrs = parent::attrs();
35
        $attrs['layout'] = $this->layout;
36
        $attrs['extensionType'] = $this->extensionType;
37
        $attrs['extensionKey'] = $this->extensionKey;
38
        if ($this->parameters) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->parameters 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...
39
            $attrs['parameters'] = $this->parameters;
40
        }
41
        $attrs['localId'] = $this->localId;
42
43
        return $attrs;
44
    }
45
}
46