TypeHintFeature::fix()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
declare (strict_types = 1);
3
4
namespace JanPiet\PhpTranspiler\Feature;
5
6
use JanPiet\PhpTranspiler\NodeSearch;
7
use PhpParser\Node;
8
9
class TypeHintFeature implements FeatureInterface
10
{
11
    private $php7OnlyTypeHints = ['int', 'string', 'float', 'bool'];
12
13
    /**
14
     * @param NodeSearch $nodeSearch
15
     * @return bool
16
     */
17 6
    public function fix(NodeSearch $nodeSearch): bool
18
    {
19 6
        $found = false;
20 6
        foreach ($nodeSearch->eachType(Node\Param::class) as $node) {
21 6
            if (!in_array($node->type, $this->php7OnlyTypeHints)) {
22 4
                continue;
23
            }
24
25 5
            $found = true;
26 5
            $node->type = null;
27
        }
28
29 6
        return $found;
30
    }
31
}
32