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

AliasCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
wmc 4
lcom 1
cbo 4

1 Method

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