Completed
Push — master ( 1ab7a3...6c56f9 )
by Дмитрий
02:57
created

UseCast::visitPhpFunctionCall()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 8.8571
cc 5
eloc 9
nc 4
nop 2
crap 30
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\FunctionCall;
4
5
use PhpParser\Node\Expr\FuncCall;
6
use PhpParser\Node\Name;
7
use PHPSA\Context;
8
9
class UseCast
10
{
11
    protected $map = array(
12
        'boolval' => 'bool',
13
        'intval' => 'int',
14
        'floatval' => 'double',
15
        'doubleval' => 'double',
16
        'strval' => 'string'
17
    );
18
19
    public function visitPhpFunctionCall(FuncCall $funcCall, Context $context)
20
    {
21
        $name = false;
22
23
        if ($funcCall->name instanceof Name && !$funcCall->name->isFullyQualified()) {
24
            $name = $funcCall->name->getFirst();
25
        }
26
27
        if ($name && isset($this->map[$name])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
28
            $context->notice(
29
                'fcall.cast',
30
                sprintf('Please use (%s) cast instead of function call.', $this->map[$name]),
31
                $funcCall
32
            );
33
        }
34
    }
35
}
36