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

RandomApiMigration::pass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 10
c 2
b 0
f 1
nc 2
nop 2
dl 0
loc 15
ccs 12
cts 12
cp 1
crap 3
rs 9.4285
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 RandomApiMigration implements PassFunctionCallInterface
15
{
16
    use ResolveExpressionTrait;
17
18
    protected $map = array(
19
        'rand' => 'mt_rand',
20
        'srand' => 'mt_srand',
21
        'getrandmax' => 'mt_getrandmax'
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 1
            $context->notice(
29 1
                'rand.api.migration',
30 1
                sprintf(
31 1
                    'Function %s() is not recommended, please use mt_%s analog instead of it.',
32 1
                    $functionName,
33
                    $functionName
34 1
                ),
35
                $funcCall
36 1
            );
37 1
        }
38 5
    }
39
}
40