Completed
Push — v3.0.0-dev ( c7f980...54069c )
by Hilmi Erdem
28:15
created

NumericNo0PasswordGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0
ccs 0
cts 13
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
A getRandomDigitWithNo0() 0 10 2
1
<?php
2
3
/*
4
 * @copyright 2018 Hilmi Erdem KEREN
5
 * @license MIT
6
 */
7
8
namespace Erdemkeren\TemporaryAccess\PasswordGenerators;
9
10
use Exception;
11
use Erdemkeren\TemporaryAccess\PasswordGeneratorInterface;
12
13
/**
14
 * Class NumericNo0PasswordGenerator.
15
 */
16
class NumericNo0PasswordGenerator extends NumericPasswordGenerator implements PasswordGeneratorInterface
17
{
18
    /**
19
     * Generate a numeric password with no zeroes.
20
     *
21
     * @param int $length
22
     *
23
     * @return string
24
     */
25
    public function generate(int $length): string
26
    {
27
        return (string) str_replace(0, $this->getRandomDigitWithNo0(), (string) parent::generate($length));
28
    }
29
30
    /**
31
     * Generate a random digit with no zeroes.
32
     *
33
     * @return int
34
     */
35
    private function getRandomDigitWithNo0()
36
    {
37
        try {
38
            $int = random_int(1, 9);
39
        } catch (Exception $e) {
40
            $int = rand(1, 9);
41
        }
42
43
        return $int;
44
    }
45
}
46