Completed
Pull Request — master (#190)
by
unknown
04:51
created

RandomApiMigration::pass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 2
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
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 PHPSA\Context;
10
11
class RandomApiMigration extends AbstractFunctionCallAnalyzer
12
{
13
    protected $map = array(
14
        'rand' => 'mt_rand',
15
        'srand' => 'mt_srand',
16
        'getrandmax' => 'mt_getrandmax'
17
    );
18
19
    public function pass(FuncCall $funcCall, Context $context)
20
    {
21
        $functionName = $this->resolveFunctionName($funcCall, $context);
22
        if ($functionName && isset($this->map[$functionName])) {
23
            $context->notice(
24
                'rand.api.migration',
25
                sprintf(
26
                    'Function %s() is not recommended, please use random_int/random_bytes (PHP 7) or mt_%s (not cryptographically secure) instead.',
27
                    $functionName,
28
                    $functionName
29
                ),
30
                $funcCall
31
            );
32
        }
33
    }
34
}
35