Completed
Pull Request — master (#176)
by
unknown
03:02
created

AliasCheck   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A pass() 0 11 3
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 PHPSA\Context;
10
11
class AliasCheck extends AbstractFunctionCallAnalyzer
12
{
13
    protected $map = array(
14
        'join' => 'implode',
15
        'sizeof' => 'count',
16
        'pos' => 'current',
17
        'strchr' => 'strstr',
18
        'show_source' => 'highlight_file',
19
        'key_exists' => 'array_key_exists',
20
        'is_real' => 'is_float',
21
        'is_double' => 'is_float',
22
        'is_integer' => 'is_int',
23
        'is_long' => 'is_int',
24
        'ini_alter' => 'ini_set',
25
        'fputs' => 'fwrite',
26
        'chop' => 'rtrim'
27
    );
28
29
    public function pass(FuncCall $funcCall, Context $context)
30
    {
31
        $functionName = $this->resolveFunctionName($funcCall, $context);
32
        if ($functionName && isset($this->map[$functionName])) {
33
            $context->notice(
34
                'fcall.alias',
35
                sprintf('%s() is an alias of another function. Use %s() instead.', $functionName, $this->map[$functionName]),
36
                $funcCall
37
            );
38
        }
39
    }
40
}
41