Completed
Push — master ( f71cbe...4414cb )
by Dan
06:14
created

FiltersBuilder::getAllowedCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SixtyNine\Cloud\Builder;
4
5
use SixtyNine\Cloud\Filters\ChangeCase;
6
use SixtyNine\Cloud\Filters\Filters;
7
use SixtyNine\Cloud\Filters\RemoveByLength;
8
use SixtyNine\Cloud\Filters\RemoveCharacters;
9
use SixtyNine\Cloud\Filters\RemoveNumbers;
10
use SixtyNine\Cloud\Filters\RemoveTrailingCharacters;
11
12
class FiltersBuilder
13
{
14
    /** @var array */
15
    protected $allowedCase;
16
    /** @var string|null */
17
    protected $case;
18
    /** @var bool */
19
    protected $removeNumbers = true;
20
    /** @var bool */
21
    protected $removeUnwanted = true;
22
    /** @var bool */
23
    protected $removeTrailing = true;
24
    /** @var int|null */
25
    protected $minLength;
26
    /** @var int|null */
27
    protected $maxLength;
28
29 13
    protected function __construct()
30
    {
31 13
        $this->allowedCase = array(
32 13
            ChangeCase::LOWERCASE,
33 13
            ChangeCase::UPPERCASE,
34 13
            ChangeCase::UCFIRST,
35
        );
36 13
    }
37
38 13
    public static function create()
39
    {
40 13
        return new self();
41
    }
42
43
    /**
44
     * @param string $case
45
     * @return FiltersBuilder
46
     */
47 1
    public function setCase($case)
48
    {
49 1
        $case = strtolower($case);
50 1
        if (in_array($case, $this->allowedCase)) {
51 1
            $this->case = $case;
52
        }
53 1
        return $this;
54
    }
55
56
    /**
57
     * @param boolean $enabled
58
     * @return FiltersBuilder
59
     */
60 6
    public function setRemoveNumbers($enabled)
61
    {
62 6
        $this->removeNumbers = (bool)$enabled;
63 6
        return $this;
64
    }
65
66
    /**
67
     * @param boolean $enabled
68
     * @return FiltersBuilder
69
     */
70 6
    public function setRemoveUnwanted($enabled)
71
    {
72 6
        $this->removeUnwanted = (bool)$enabled;
73 6
        return $this;
74
    }
75
76
    /**
77
     * @param boolean $enabled
78
     * @return FiltersBuilder
79
     */
80 6
    public function setRemoveTrailing($enabled)
81
    {
82 6
        $this->removeTrailing = (bool)$enabled;
83 6
        return $this;
84
    }
85
86
    /**
87
     * @param int $maxLength
88
     * @return FiltersBuilder
89
     */
90 2
    public function setMaxLength($maxLength)
91
    {
92 2
        $this->maxLength = $maxLength;
93 2
        return $this;
94
    }
95
96
    /**
97
     * @param int $minLength
98
     * @return FiltersBuilder
99
     */
100 2
    public function setMinLength($minLength)
101
    {
102 2
        $this->minLength = $minLength;
103 2
        return $this;
104
    }
105
106
    /**
107
     * @return string[]
108
     */
109
    public function getAllowedCase()
110
    {
111
        return $this->allowedCase;
112
    }
113
114
    /**
115
     * @return Filters
116
     */
117 13
    public function build()
118
    {
119 13
        $filters = new Filters();
120
121 13
        if (null !== $this->case) {
122 1
            $filters->addFilter(new ChangeCase($this->case));
123
        }
124
125 13
        if ($this->removeNumbers) {
126 8
            $filters->addFilter(new RemoveNumbers());
127
        }
128
129 13
        if ($this->removeUnwanted) {
130 8
            $filters->addFilter(new RemoveCharacters());
131
        }
132
133 13
        if ($this->removeTrailing) {
134 8
            $filters->addFilter(new RemoveTrailingCharacters());
135
        }
136
137 13
        if (null !== $this->minLength || null !== $this->maxLength) {
138 2
            $filters->addFilter(new RemoveByLength($this->minLength, $this->maxLength));
139
        }
140
141 13
        return $filters;
142
    }
143
}