NodeStripper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A leaveNode() 0 8 2
1
<?php
2
/**
3
 * This program is free software. It comes without any warranty, to
4
 * the extent permitted by applicable law. You can redistribute it
5
 * and/or modify it under the terms of the Do What The Fuck You Want
6
 * To Public License, Version 2, as published by Sam Hocevar. See
7
 * http://www.wtfpl.net/ for more details.
8
 */
9
10
declare(strict_types = 1);
11
12
namespace hanneskod\classtools\Transformer\Action;
13
14
use PhpParser\NodeVisitorAbstract;
15
use PhpParser\Node;
16
use PhpParser\NodeTraverser;
17
18
/**
19
 * Strip nodes of registered type
20
 *
21
 * @author Hannes Forsgård <[email protected]>
22
 */
23
class NodeStripper extends NodeVisitorAbstract
24
{
25
    /**
26
     * @var string Name of node to strip
27
     */
28
    private $nodeType;
29
30
    /**
31
     * Register what nodes to strip using a fully quilified PhpParser class name
32
     *
33
     * @param string $nodeType Node type (see Node::getType())
34
     */
35
    public function __construct(string $nodeType)
36
    {
37
        $this->nodeType = $nodeType;
38
    }
39
40
    public function leaveNode(Node $node)
41
    {
42
        if ($node->getType() == $this->nodeType) {
43
            return NodeTraverser::REMOVE_NODE;
44
        }
45
46
        return null;
47
    }
48
}
49