Completed
Push — master ( 4eb3b6...7be634 )
by Freek
05:29 queued 03:34
created

ScalarTypeHintsRemover::leaveNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Php7to5;
4
5
use PhpParser\Node;
6
use PhpParser\Node\FunctionLike;
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 FunctionLike) {
17
            $node->returnType = null;
0 ignored issues
show
Bug introduced by
Accessing returnType on the interface PhpParser\Node\FunctionLike suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
18
        }
19
    }
20
}
21