Completed
Push — master ( 6c3584...3bd08b )
by Дмитрий
02:31
created

AliasCheck::pass()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20
Metric Value
cc 4
eloc 14
nc 3
nop 2
dl 0
loc 23
ccs 0
cts 17
cp 0
crap 20
rs 8.7972
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\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 AliasCheck implements PassFunctionCallInterface
14
{
15
    protected $map = array(
16
        'join' => 'implode',
17
        'sizeof' => 'count'
18
    );
19
20
    public function pass(FuncCall $funcCall, Context $context)
21
    {
22
        $funcNameCompiledExpression = $context->getExpressionCompiler()->compile($funcCall->name);
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $funcNameCompiledExpression exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
23
24
        if ($funcNameCompiledExpression->isString() && $funcNameCompiledExpression->isCorrectValue()) {
25
            $name = $funcNameCompiledExpression->getValue();
26
        } else {
27
            $context->debug(
28
                'Unexpected function name type ' . $funcNameCompiledExpression->getType(),
29
                $funcCall->name
30
            );
31
32
            return false;
33
        }
34
35
        if (isset($this->map[$name])) {
36
            $context->notice(
37
                'fcall.alias',
38
                sprintf('%s() is an alias of function. Use %s(...).', $name, $this->map[$name]),
39
                $funcCall
40
            );
41
        }
42
    }
43
}
44