DefineArrayReplacer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 0 21 4
1
<?php
2
3
namespace Spatie\Php7to5\NodeVisitors;
4
5
use PhpParser\Node;
6
use PhpParser\NodeVisitorAbstract;
7
8
/*
9
 * Converts define() arrays into const arrays
10
 */
11
12
class DefineArrayReplacer extends NodeVisitorAbstract
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function leaveNode(Node $node)
18
    {
19
        if (!$node instanceof Node\Expr\FuncCall) {
20
            return;
21
        }
22
23
        if ($node->name != 'define') {
24
            return;
25
        }
26
27
        $nameNode = $node->args[0]->value;
28
        $valueNode = $node->args[1]->value;
29
30
        if (!$valueNode instanceof Node\Expr\Array_) {
31
            return;
32
        }
33
34
        $constNode = new Node\Const_($nameNode->value, $valueNode);
35
36
        return new Node\Stmt\Const_([$constNode]);
37
    }
38
}
39