Completed
Push — master ( 6f5389...c76b00 )
by Eugene
01:08
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
/**
4
 * This file is part of the rybakit/twig-deferred-extension package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Twig\DeferredExtension;
15
16
use Twig\Environment;
17
use Twig\Node\ModuleNode;
18
use Twig\Node\Node;
19
use Twig\NodeVisitor\NodeVisitorInterface;
20
21
final class DeferredNodeVisitor implements NodeVisitorInterface
22
{
23
    private $hasDeferred = false;
24
25
    public function enterNode(Node $node, Environment $env) : Node
26
    {
27
        if (!$this->hasDeferred && $node instanceof DeferredBlockNode) {
28
            $this->hasDeferred = true;
29
        }
30
31
        return $node;
32
    }
33
34
    public function leaveNode(Node $node, Environment $env) : ?Node
35
    {
36
        if ($this->hasDeferred && $node instanceof ModuleNode) {
37
            $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...
38
            $this->hasDeferred = false;
39
        }
40
41
        return $node;
42
    }
43
44
    public function getPriority() : int
45
    {
46
        return 0;
47
    }
48
}
49