Completed
Pull Request — master (#176)
by
unknown
03:02
created

RandomApiMigration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A pass() 0 15 3
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