Completed
Push — master ( bd3178...998f3f )
by Christoffer
04:52 queued 02:42
created

Visitor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enterNode() 0 9 2
A leaveNode() 0 9 2
1
<?php
2
3
namespace Digia\GraphQL\Language\AST\Visitor;
4
5
use Digia\GraphQL\Language\AST\Node\NodeInterface;
6
7
class Visitor extends AbstractVisitor
8
{
9
10
    /**
11
     * @var callable|null
12
     */
13
    protected $enterFunction;
14
15
    /**
16
     * @var callable|null
17
     */
18
    protected $leaveFunction;
19
20
    /**
21
     * TestableVisitor constructor.
22
     * @param callable|null $enterFunction
23
     * @param callable|null $leaveFunction
24
     */
25
    public function __construct(?callable $enterFunction = null, ?callable $leaveFunction = null)
26
    {
27
        $this->enterFunction = $enterFunction;
28
        $this->leaveFunction = $leaveFunction;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function enterNode(
35
        NodeInterface $node,
36
        $key = null,
37
        ?NodeInterface $parent = null,
38
        array $path = []
39
    ): ?NodeInterface {
40
        return null !== $this->enterFunction
41
            ? call_user_func($this->enterFunction, $node, $key, $parent, $path)
42
            : $node;
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function leaveNode(
49
        NodeInterface $node,
50
        $key = null,
51
        ?NodeInterface $parent = null,
52
        array $path = []
53
    ): ?NodeInterface {
54
        return null !== $this->leaveFunction
55
            ? call_user_func($this->leaveFunction, $node, $key, $parent, $path)
56
            : $node;
57
    }
58
}
59