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

NumericNo0TokenGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlainText() 12 12 2
A getRandomDigitWithNo0() 0 10 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
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