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

DummyPasswordGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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