Completed
Push — master ( fc51f9...b3b654 )
by Freek
03:59
created

EmptyDeclareStatementRemover::leaveNode()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace Spatie\Php7to5\NodeVisitors;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Stmt\Declare_;
7
use PhpParser\Node\Stmt\DeclareDeclare;
8
use PhpParser\NodeTraverser;
9
use PhpParser\NodeVisitorAbstract;
10
11
class EmptyDeclareStatementRemover extends NodeVisitorAbstract
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function leaveNode(Node $node)
17
    {
18
        if (!$node instanceof Declare_) {
19
            return;
20
        }
21
22
        $result = array_filter(array_map(function (DeclareDeclare $declare) {
23
            return $declare->key !== 'strict_types';
24
        }, $node->declares));
25
26
        if (empty($result)) {
27
            return NodeTraverser::REMOVE_NODE;
28
        }
29
    }
30
}
31