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

DebugCode   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 1
cbo 5
dl 0
loc 33
ccs 0
cts 17
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C visitPhpFunctionCall() 0 25 7
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