Completed
Push — master ( 981259...d281bf )
by Дмитрий
02:51
created

RandomApiMigration::pass()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 24
ccs 0
cts 18
cp 0
crap 20
rs 8.6845
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\Compiler\Expression;
11
use PHPSA\Context;
12
13
class RandomApiMigration implements PassFunctionCallInterface
14
{
15
    protected $map = array(
16
        'rand' => 'mt_rand',
17
        'srand' => 'mt_srand',
18
        'getrandmax' => 'mt_getrandmax'
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
            $context->notice(
39
                'rand.api.migration',
40
                sprintf('Function %s() is not recommended, please use mt_%s analog instead of it.', $name, $name),
41
                $funcCall
42
            );
43
        }
44
    }
45
}
46