StrictTypesFeature   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 35
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B fix() 0 27 5
1
<?php declare (strict_types = 1);
2
3
4
namespace JanPiet\PhpTranspiler\Feature;
5
6
use JanPiet\PhpTranspiler\NodeSearch;
7
use PhpParser\Node\Stmt\Declare_;
8
use PhpParser\Node\Stmt\DeclareDeclare;
9
10
class StrictTypesFeature implements FeatureInterface
11
{
12
13
    /**
14
     * @param NodeSearch $nodeSearch
15
     * @return bool
16
     */
17 2
    public function fix(NodeSearch $nodeSearch): bool
18
    {
19 2
        $found = false;
20
21 2
        foreach ($nodeSearch->eachType(Declare_::class) as $declareNode) {
22 2
            $newDeclares = [];
23
24
            /** @var DeclareDeclare $declareStatement */
25 2
            foreach ($declareNode->declares as $declareStatement) {
26 2
                if ($declareStatement->key === 'strict_types') {
27 2
                    $found = true;
28 2
                    continue;
29
                }
30
31
                $newDeclares[] = $declareNode;
32
            }
33
34 2
            if ($newDeclares) {
35
                $declareNode->declares = $newDeclares;
36
                continue;
37
            }
38
39 2
            $nodeSearch->removeNode($declareNode);
40
        }
41
42 2
        return $found;
43
    }
44
}
45