Completed
Push — master ( fc51f9...b3b654 )
by Freek
03:59
created

NullCoalesceReplacer::leaveNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Php7to5\NodeVisitors;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Expr\BinaryOp\Coalesce;
7
use PhpParser\NodeVisitorAbstract;
8
9
class NullCoalesceReplacer extends NodeVisitorAbstract
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function leaveNode(Node $node)
15
    {
16
        if (!$node instanceof Coalesce) {
17
            return;
18
        }
19
20
        $issetCall = new Node\Expr\FuncCall(new Node\Name('isset'), [$node->left]);
0 ignored issues
show
Documentation introduced by
array($node->left) is of type array<integer,object<Php...pParser\\Node\\Expr>"}>, but the function expects a array<integer,object<PhpParser\Node\Arg>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
22
        return new Node\Expr\Ternary($issetCall, $node->left, $node->right);
23
    }
24
}
25