Generator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 50
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMethod() 0 7 2
A generate() 0 13 2
1
<?php
2
3
namespace iiifx\PasswordGenerator;
4
5
use iiifx\PasswordGenerator\Method\MethodMT;
6
use iiifx\PasswordGenerator\Method\MethodInterface;
7
8
class Generator
9
{
10
    /**
11
     * @var Options
12
     */
13
    protected $options;
14
15
    /**
16
     * @var MethodInterface
17
     */
18
    protected $method;
19
20
    /**
21
     * @param Options         $options
22
     * @param MethodInterface $method
23
     */
24 2
    public function __construct ( Options $options, MethodInterface $method = null )
25
    {
26 2
        $this->options = $options;
27 2
        $this->method = $method;
28 2
    }
29
30
    /**
31
     * @return MethodInterface
32
     */
33 1
    public function getMethod ()
34
    {
35 1
        if ( !$this->method instanceof MethodInterface ) {
36 1
            $this->method = new MethodMT();
37 1
        }
38 1
        return $this->method;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 1
    public function generate ()
45
    {
46 1
        $password = '';
47 1
        $map = $this->options->createHitRateMap();
48 1
        $limit = count( $map ) - 1;
49 1
        $length = $this->options->createLength();
50 1
        for ( $i = 0; $i < $length; $i++ ) {
51 1
            $position = $this->getMethod()->getRandomInt( $limit );
52 1
            $symbols = $map[ $position ];
53 1
            $password .= $symbols->getRandomSymbol( $this->getMethod() );
54 1
        }
55 1
        return $password;
56
    }
57
}
58