Completed
Push — master ( 0fb455...ba0b4e )
by Hilmi Erdem
03:52 queued 02:19
created

NumericTokenGenerator::generateRangeForLength()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Erdemkeren\TemporaryAccess\Token\TokenGenerator;
4
5
use Exception;
6
7
class NumericTokenGenerator extends AbstractTokenGenerator implements TokenGeneratorInterface
8
{
9 1 View Code Duplication
    protected function getPlainText($length)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
    {
11 1
        $range = $this->generateRangeForLength($length);
12
13
        try {
14 1
            $int = random_int($range[0], $range[1]);
15 1
        } catch (Exception $e) {
16 1
            $int = rand($range[0], $range[1]);
17
        }
18
19 1
        return (string) $int;
20
    }
21
22 3
    protected function generateRangeForLength($length)
23
    {
24 3
        $min = 1;
25 3
        $max = 9;
26
27 3
        while($length > 1) {
28 3
            $min .= 0;
29 3
            $max .= 9;
30
31 3
            --$length;
32 3
        }
33
34
        return [
35 3
            $min, $max
36 3
        ];
37
    }
38
}
39