Completed
Push — development ( 1fb984...7ea9e3 )
by Nils
08:29
created

DummyPasswordGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 10
loc 54
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A generatePassword() 0 10 2
A getLength() 0 4 1
A setLength() 10 10 3

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 PasswordGenerator\Generator;
4
5
use PasswordGenerator\Model\Option\Option;
6
7
class DummyPasswordGenerator extends AbstractPasswordGenerator
8
{
9
    const OPTION_LENGTH = 'LENGTH';
10
11
    /**
12
     */
13
    public function __construct()
14
    {
15
        $this
16
            ->setOption(self::OPTION_LENGTH, array('type' => Option::TYPE_INTEGER, 'default' => 10))
17
        ;
18
    }
19
20
    public function generatePassword()
21
    {
22
        $length = $this->getOptionValue(self::OPTION_LENGTH);
23
24
        if ($length < 8) {
25
            return \substr('password', 0, $length);
26
        }
27
28
        return str_pad('password', $length, '?');
29
    }
30
31
    /**
32
     * Password length.
33
     *
34
     * @return int
35
     */
36
    public function getLength()
37
    {
38
        return $this->getOptionValue(self::OPTION_LENGTH);
39
    }
40
41
    /**
42
     * Set length of desired password(s).
43
     *
44
     * @param int $characterCount
45
     *
46
     * @return $this
47
     *
48
     * @throws \InvalidArgumentException
49
     */
50 View Code Duplication
    public function setLength($characterCount)
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...
51
    {
52
        if (!is_int($characterCount) || $characterCount < 1) {
53
            throw new \InvalidArgumentException('Expected positive integer');
54
        }
55
56
        $this->setOptionValue(self::OPTION_LENGTH, $characterCount);
57
58
        return $this;
59
    }
60
}
61