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

NumericTokenGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 12
loc 32
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlainText() 12 12 2
A generateRangeForLength() 0 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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