Completed
Push — master ( 150606...e60be2 )
by Freek
01:44
created

ScalarTypeHintsRemover::leaveNode()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace Spatie\Php7to5;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Param;
7
use PhpParser\NodeVisitorAbstract;
8
9
class ScalarTypeHintsRemover extends NodeVisitorAbstract
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function leaveNode(Node $node)
15
    {
16
        if ($node instanceof Param) {
17
            if ($this->isScalar($node->type)) {
18
                $node->type = null;
19
            }
20
        }
21
    }
22
23
    /**
24
     * @param $type
25
     *
26
     * @return bool
27
     */
28
    protected function isScalar($type) : bool
29
    {
30
        return in_array($type, ['int', 'integer', 'float', 'string', 'bool', 'boolean']);
31
    }
32
}
33