Completed
Push — master ( 70d6a4...bef242 )
by Samuel
02:26
created

Text   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 58
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaults() 0 7 1
A setPool() 0 4 1
A setMinLength() 0 4 1
A setMaxLength() 0 4 1
A setLength() 0 4 1
A doRandomization() 0 16 4
A stringify() 0 4 1
1
<?php
2
3
namespace Samshal\Rando\Packages\Basics;
4
5
use Samshal\Rando\Packages\PackageableInterface;
6
use Samshal\Rando\Packages\Packages;
7
use Samshal\Rando\Rando;
8
9
class Text extends Packages implements PackageableInterface
10
{
11
12
    protected $pool;
13
    protected $minLength;
14
    protected $maxLength;
15
    protected $length;
16
17
    public function setDefaults($defaultsArray = [])
18
    {
19
        $defaultsArray['minLength'] = 5;
20
        $defaultsArray['maxLength'] = 20;
21
22
        return $defaultsArray;
23
    }
24
25
    protected function setPool($pool)
26
    {
27
        $this->pool = $pool;
28
    }
29
30
    protected function setMinLength($min)
31
    {
32
        $this->minLength = $min;
33
    }
34
35
    protected function setMaxLength($max)
36
    {
37
        $this->maxLength = $max;
38
    }
39
40
    protected function setLength($length)
41
    {
42
        $this->length = $length;
43
    }
44
45
    private function doRandomization()
46
    {
47
        $length = (!empty($this->length)) ? $this->length : Rando::integer(['min'=>$this->minLength, 'max'=>$this->maxLength]);
48
        $string = '';
49
        while ($length > 0) {
50
            if (empty($this->pool)) {
51
                $string .= Rando::character();
52
            } else {
53
                $string .= Rando::character(['pool'=>$this->pool]);
54
            }
55
56
            $length--;
57
        }
58
59
        return $string;
60
    }
61
62
    public function stringify()
63
    {
64
        return self::doRandomization();
65
    }
66
}
67