EasyHtmlElementExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A load() 0 9 1
1
<?php
2
3
namespace NatePage\EasyHtmlElement\Bridge\Twig;
4
5
use NatePage\EasyHtmlElement\HtmlElementInterface;
6
use NatePage\EasyHtmlElement\ElementInterface;
7
8
class EasyHtmlElementExtension extends \Twig_Extension
9
{
10
    /** @var HtmlElementInterface */
11
    private $htmlElement;
12
13
    public function __construct(HtmlElementInterface $htmlElement)
14
    {
15
        $this->htmlElement = $htmlElement;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getFunctions(): array
22
    {
23
        return array(
24
            new \Twig_Function('htmlElement', array($this, 'load'), array('is_safe' => array('html')))
25
        );
26
    }
27
28
    /**
29
     * Load a html element.
30
     *
31
     * @param string|array $name       The element name
32
     * @param array        $parameters The element parameters
33
     * @param array        $attributes The element attributes
34
     * @param array        $children   The element children
35
     *
36
     * @return ElementInterface
37
     */
38
    public function load(
39
        $name,
40
        array $parameters = array(),
41
        array $attributes = array(),
42
        array $children = array()
43
    ): ElementInterface
44
    {
45
        return $this->htmlElement->load($name, $parameters, $attributes, $children);
0 ignored issues
show
Documentation introduced by
$parameters is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
    }
47
}
48