Completed
Push — master ( 3a46ea...cc3bc4 )
by Freek
02:08
created

DefineArrayReplacer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 25
rs 10

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
    public function leaveNode(Node $node)
15
    {
16
        if (!$node instanceof Node\Expr\FuncCall) {
17
            return null;
18
        }
19
20
        if ($node->name != 'define') {
21
            return null;
22
        }
23
24
        $nameNode = $node->args[0]->value;
25
        $valueNode = $node->args[1]->value;
26
27
        if (! $valueNode instanceof Node\Expr\Array_) {
28
            return null;
29
        }
30
31
        $constNode = new Node\Const_($nameNode->value, $valueNode);
32
33
        return new Node\Stmt\Const_([$constNode]);
34
    }
35
36
}