Completed
Push — master ( cccec0...62a534 )
by Дмитрий
06:20
created

DebugCode::visitPhpFunctionCall()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 25
ccs 0
cts 17
cp 0
rs 6.7273
cc 7
eloc 13
nc 8
nop 2
crap 56
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\FunctionCall;
4
5
use PhpParser\Node\Expr\FuncCall;
6
use PhpParser\Node\Name;
7
use PHPSA\Context;
8
9
class DebugCode
10
{
11
    protected $map = array(
12
        'var_dump' => 'var_dump',
13
        'var_export' => 'var_export'
14
    );
15
16
    public function visitPhpFunctionCall(FuncCall $funcCall, Context $context)
17
    {
18
        $name = false;
19
20
        if ($funcCall->name instanceof Name && !$funcCall->name->isFullyQualified()) {
21
            $name = $funcCall->name->getFirst();
22
        }
23
24
        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...
25
            if ($funcCall->getDocComment()) {
26
                $phpdoc = new \phpDocumentor\Reflection\DocBlock($funcCall->getDocComment()->getText());
27
                if ($phpdoc->hasTag('expected')) {
28
                    return true;
29
                }
30
31
//                return true;
32
            }
33
34
            $context->notice(
35
                'debug.code',
36
                sprintf('Function %s() is a debug code, please don`t use it in production.', $name),
37
                $funcCall
38
            );
39
        }
40
    }
41
}
42