EmptyDeclareStatementRemover::leaveNode()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
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