Completed
Push — master ( b7cb0e...ffcfdb )
by Дмитрий
02:53
created

DebugCode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10
wmc 5
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B pass() 0 18 5
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 PhpParser\Node\Name;
10
use PHPSA\Analyzer\Helper\ResolveExpressionTrait;
11
use PHPSA\Compiler\Expression;
12
use PHPSA\Context;
13
14
class DebugCode implements PassFunctionCallInterface
15
{
16
    use ResolveExpressionTrait;
17
18
    protected $map = array(
19
        'var_dump' => 'var_dump',
20
        'var_export' => 'var_export',
21
        'debug_zval_dump' => 'debug_zval_dump'
22
    );
23
24 5
    public function pass(FuncCall $funcCall, Context $context)
25
    {
26 5
        $functionName = $this->resolveFunctionName($funcCall, $context);
27 5
        if ($functionName && isset($this->map[$functionName])) {
28 2
            if ($funcCall->getDocComment()) {
29 1
                $phpdoc = new \phpDocumentor\Reflection\DocBlock($funcCall->getDocComment()->getText());
30 1
                if ($phpdoc->hasTag('expected')) {
31 1
                    return true;
32
                }
33 1
            }
34
35 2
            $context->notice(
36 2
                'debug.code',
37 2
                sprintf('Function %s() is a debug code, please don`t use it in production.', $functionName),
38
                $funcCall
39 2
            );
40 2
        }
41 5
    }
42
}
43