Completed
Pull Request — master (#9)
by Eugene
03:48
created

DeferredNodeVisitor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enterNode() 0 8 3
A leaveNode() 0 9 3
A getPriority() 0 4 1
1
<?php
2
3
namespace Twig\DeferredExtension;
4
5
use Twig\Environment;
6
use Twig\Node\ModuleNode;
7
use Twig\Node\Node;
8
use Twig\NodeVisitor\NodeVisitorInterface;
9
10
final class DeferredNodeVisitor implements NodeVisitorInterface
11
{
12
    private $hasDeferred = false;
13
14
    public function enterNode(Node $node, Environment $env): Node
15
    {
16
        if (!$this->hasDeferred && $node instanceof DeferredBlockNode) {
17
            $this->hasDeferred = true;
18
        }
19
20
        return $node;
21
    }
22
23
    public function leaveNode(Node $node, Environment $env): ?Node
24
    {
25
        if ($this->hasDeferred && $node instanceof ModuleNode) {
26
            $node->setNode('display_end', new Node([new DeferredNode(), $node->getNode('display_end')]));
0 ignored issues
show
Documentation introduced by
new \Twig\Node\Node(arra...etNode('display_end'))) is of type object<Twig\Node\Node>, but the function expects a object<self>.

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...
27
            $this->hasDeferred = false;
28
        }
29
30
        return $node;
31
    }
32
33
    public function getPriority()
34
    {
35
        return 0;
36
    }
37
}
38