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

NumericNo0TokenGenerator::getRandomDigitWithNo0()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Erdemkeren\TemporaryAccess\Token\TokenGenerator;
4
5
use Exception;
6
7
final class NumericNo0TokenGenerator extends NumericTokenGenerator implements TokenGeneratorInterface
8
{
9 2 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 2
        $range = $this->generateRangeForLength($length);
12
13
        try {
14 2
            $int = random_int($range[0], $range[1]);
15 2
        } catch (Exception $e) {
16 2
            $int = rand($range[0], $range[1]);
17
        }
18
19 2
        return (string) str_replace(0, $this->getRandomDigitWithNo0(), (string) $int);
20
    }
21
22 2
    private function getRandomDigitWithNo0()
23
    {
24
        try {
25 2
            $int = random_int(1, 9);
26 2
        } catch (Exception $e) {
27 2
            $int = rand(1, 9);
28
        }
29
30 2
        return $int;
31
    }
32
}
33