Completed
Push — master ( dbf708...cb3635 )
by Дмитрий
03:13
created

UseCast::pass()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 5
eloc 9
c 2
b 0
f 1
nc 3
nop 2
dl 0
loc 18
ccs 11
cts 11
cp 1
crap 5
rs 8.8571
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Expression\FunctionCall;
7
8
use PhpParser\Node\Expr\FuncCall;
9
use PhpParser\Node\Name;
10
use PHPSA\Compiler\Expression;
11
use PHPSA\Context;
12
13
class UseCast extends AbstractFunctionCallAnalyzer
14
{
15
    protected $map = array(
16
        'boolval' => 'bool',
17
        'intval' => 'int',
18
        'floatval' => 'double',
19
        'doubleval' => 'double',
20
        'strval' => 'string'
21
    );
22
23 7
    public function pass(FuncCall $funcCall, Context $context)
24
    {
25 7
        $functionName = $this->resolveFunctionName($funcCall, $context);
26 7
        if ($functionName && isset($this->map[$functionName])) {
27
            /**
28
             * Exclusion via intval with 2 args intval($number, int $base = 10);
29
             */
30 1
            if ($functionName == 'intval' && count($funcCall->args) > 1) {
31 1
                return;
32
            }
33
34 1
            $context->notice(
35 1
                'fcall.cast',
36 1
                sprintf('Please use (%s) cast instead of function call.', $this->map[$functionName]),
37
                $funcCall
38 1
            );
39 1
        }
40 7
    }
41
}
42