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

Text::setPool()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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