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

DebugCode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B pass() 0 31 6
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 DebugCode implements PassFunctionCallInterface
14
{
15
    protected $map = array(
16
        'var_dump' => 'var_dump',
17
        'var_export' => 'var_export',
18
        'debug_zval_dump' => 'debug_zval_dump'
19
    );
20
21
    public function pass(FuncCall $funcCall, Context $context)
22
    {
23
        $compiler = $context->getExpressionCompiler();
24
        $funcNameCompiledExpression = $compiler->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...
25
26
        if ($funcNameCompiledExpression->isString() && $funcNameCompiledExpression->isCorrectValue()) {
27
            $name = $funcNameCompiledExpression->getValue();
28
        } else {
29
            $context->debug(
30
                'Unexpected function name type ' . $funcNameCompiledExpression->getType(),
31
                $funcCall->name
32
            );
33
34
            return false;
35
        }
36
37
        if (isset($this->map[$name])) {
38
            if ($funcCall->getDocComment()) {
39
                $phpdoc = new \phpDocumentor\Reflection\DocBlock($funcCall->getDocComment()->getText());
40
                if ($phpdoc->hasTag('expected')) {
41
                    return true;
42
                }
43
            }
44
45
            $context->notice(
46
                'debug.code',
47
                sprintf('Function %s() is a debug code, please don`t use it in production.', $name),
48
                $funcCall
49
            );
50
        }
51
    }
52
}
53