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

UseCast   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 31
ccs 10
cts 11
cp 0.9091
rs 10
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B pass() 0 18 5
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