Completed
Push — master ( 754bf8...dc3502 )
by Дмитрий
05:36
created

AliasCheck   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 23
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B visitPhpFunctionCall() 0 16 5
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\Context;
11
12
class AliasCheck implements PassFunctionCallInterface
13
{
14
    protected $map = array(
15
        'join' => 'implode'
16
    );
17
18
    public function visitPhpFunctionCall(FuncCall $funcCall, Context $context)
19
    {
20
        $name = false;
21
22
        if ($funcCall->name instanceof Name && !$funcCall->name->isFullyQualified()) {
23
            $name = $funcCall->name->getFirst();
24
        }
25
26
        if ($name && isset($this->map[$name])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
27
            $context->notice(
28
                'fcall.alias',
29
                sprintf('%s() is an alias of function. Use %s(...).', $name, $this->map[$name]),
30
                $funcCall
31
            );
32
        }
33
    }
34
}
35