EmptyDeclareStatementRemover   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 0 14 3
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