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

ScalarTypeHintsRemover   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 24
rs 10

2 Methods

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