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

ScalarTypeHintsRemover::isScalar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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