Completed
Push — master ( b7cb0e...ffcfdb )
by Дмитрий
02:53
created

UseCast::pass()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.0187

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 10
cts 11
cp 0.9091
crap 5.0187
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\Analyzer\Helper\ResolveExpressionTrait;
11
use PHPSA\Compiler\Expression;
12
use PHPSA\Context;
13
14
class UseCast implements PassFunctionCallInterface
15
{
16
    use ResolveExpressionTrait;
17
18
    protected $map = array(
19
        'boolval' => 'bool',
20
        'intval' => 'int',
21
        'floatval' => 'double',
22
        'doubleval' => 'double',
23
        'strval' => 'string'
24
    );
25
26 5
    public function pass(FuncCall $funcCall, Context $context)
27
    {
28 5
        $functionName = $this->resolveFunctionName($funcCall, $context);
29 5
        if ($functionName && isset($this->map[$functionName])) {
30
            /**
31
             * Exclusion via intval with 2 args intval($number, int $base = 10);
32
             */
33 1
            if ($functionName == 'intval' && count($funcCall->args) > 1) {
34
                return;
35
            }
36
37 1
            $context->notice(
38 1
                'fcall.cast',
39 1
                sprintf('Please use (%s) cast instead of function call.', $this->map[$functionName]),
40
                $funcCall
41 1
            );
42 1
        }
43 5
    }
44
}
45