Total Complexity | 42 |
Total Lines | 305 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like Mailcode_Factory_CommandSets_Set_If often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Mailcode_Factory_CommandSets_Set_If, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Mailcode_Factory_CommandSets_Set_If extends Mailcode_Factory_CommandSets_IfBase |
||
22 | { |
||
23 | public function if(string $condition, string $type='') : Mailcode_Commands_Command_If |
||
33 | } |
||
34 | |||
35 | public function var(string $variable, string $operand, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_If_Variable |
||
36 | { |
||
37 | $command = $this->instantiator->buildIfVar('If', $variable, $operand, $value, $quoteValue, $insensitive); |
||
38 | |||
39 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
40 | { |
||
41 | return $command; |
||
42 | } |
||
43 | |||
44 | throw $this->instantiator->exceptionUnexpectedType('IfVar', $command); |
||
45 | } |
||
46 | |||
47 | public function varString(string $variable, string $operand, string $value, bool $insensitive=false) : Mailcode_Commands_Command_If_Variable |
||
48 | { |
||
49 | $command = $this->instantiator->buildIfVar('If', $variable, $operand, $value, true, $insensitive); |
||
50 | |||
51 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
52 | { |
||
53 | return $command; |
||
54 | } |
||
55 | |||
56 | throw $this->instantiator->exceptionUnexpectedType('IfVarString', $command); |
||
57 | } |
||
58 | |||
59 | public function varEquals(string $variable, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_If_Variable |
||
60 | { |
||
61 | $command = $this->instantiator->buildIfVar('If', $variable, '==', $value, $quoteValue, $insensitive); |
||
62 | |||
63 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
64 | { |
||
65 | return $command; |
||
66 | } |
||
67 | |||
68 | throw $this->instantiator->exceptionUnexpectedType('IfVarEquals', $command); |
||
69 | } |
||
70 | |||
71 | public function varEqualsString(string $variable, string $value, bool $insensitive=false) : Mailcode_Commands_Command_If |
||
72 | { |
||
73 | $command = $this->instantiator->buildIfVar('If', $variable, '==', $value, true, $insensitive); |
||
74 | |||
75 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
76 | { |
||
77 | return $command; |
||
78 | } |
||
79 | |||
80 | throw $this->instantiator->exceptionUnexpectedType('IfVarEqualsString', $command); |
||
81 | } |
||
82 | |||
83 | public function varNotEquals(string $variable, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_If_Variable |
||
84 | { |
||
85 | $command = $this->instantiator->buildIfVar('If', $variable, '!=', $value, $quoteValue, $insensitive); |
||
86 | |||
87 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
88 | { |
||
89 | return $command; |
||
90 | } |
||
91 | |||
92 | throw $this->instantiator->exceptionUnexpectedType('IfVarNotEquals', $command); |
||
93 | } |
||
94 | |||
95 | public function varNotEqualsString(string $variable, string $value, bool $insensitive=false) : Mailcode_Commands_Command_If_Variable |
||
96 | { |
||
97 | $command = $this->instantiator->buildIfVar('If', $variable, '!=', $value, true, $insensitive); |
||
98 | |||
99 | if($command instanceof Mailcode_Commands_Command_If_Variable) |
||
100 | { |
||
101 | return $command; |
||
102 | } |
||
103 | |||
104 | throw $this->instantiator->exceptionUnexpectedType('IfVarNotEqualsString', $command); |
||
105 | } |
||
106 | |||
107 | public function empty(string $variable) : Mailcode_Commands_Command_If_Empty |
||
108 | { |
||
109 | $command = $this->instantiator->buildIfEmpty('If', $variable); |
||
110 | |||
111 | if($command instanceof Mailcode_Commands_Command_If_Empty) |
||
112 | { |
||
113 | return $command; |
||
114 | } |
||
115 | |||
116 | throw $this->instantiator->exceptionUnexpectedType('IfEmpty', $command); |
||
117 | } |
||
118 | |||
119 | public function notEmpty(string $variable) : Mailcode_Commands_Command_If_NotEmpty |
||
120 | { |
||
121 | $command = $this->instantiator->buildIfNotEmpty('If', $variable); |
||
122 | |||
123 | if($command instanceof Mailcode_Commands_Command_If_NotEmpty) |
||
124 | { |
||
125 | return $command; |
||
126 | } |
||
127 | |||
128 | throw $this->instantiator->exceptionUnexpectedType('IfNotEmpty', $command); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @param string $variable |
||
133 | * @param string[] $searchTerms |
||
134 | * @param bool $caseInsensitive |
||
135 | * @return Mailcode_Commands_Command_If_Contains |
||
136 | * @throws Mailcode_Factory_Exception |
||
137 | */ |
||
138 | public function contains(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_Contains |
||
139 | { |
||
140 | $command = $this->instantiator->buildIfContains('If', $variable, $searchTerms, $caseInsensitive); |
||
141 | |||
142 | if($command instanceof Mailcode_Commands_Command_If_Contains) |
||
143 | { |
||
144 | return $command; |
||
145 | } |
||
146 | |||
147 | throw $this->instantiator->exceptionUnexpectedType('IfContains', $command); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @param string $variable |
||
152 | * @param string[] $searchTerms |
||
153 | * @param bool $caseInsensitive |
||
154 | * @return Mailcode_Commands_Command_If_NotContains |
||
155 | * @throws Mailcode_Factory_Exception |
||
156 | */ |
||
157 | public function notContains(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_NotContains |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @param string $variable |
||
171 | * @param string[] $searchTerms |
||
172 | * @param bool $caseInsensitive |
||
173 | * @param bool $regexEnabled |
||
174 | * @return Mailcode_Commands_Command_If_ListContains |
||
175 | * @throws Mailcode_Factory_Exception |
||
176 | */ |
||
177 | public function listContains(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_If_ListContains |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @param string $variable |
||
191 | * @param string[] $searchTerms |
||
192 | * @param bool $caseInsensitive |
||
193 | * @return Mailcode_Commands_Command_If_ListEquals |
||
194 | * @throws Mailcode_Factory_Exception |
||
195 | */ |
||
196 | public function listEquals(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_ListEquals |
||
197 | { |
||
198 | $command = $this->instantiator->buildIfListContains('If', $variable, $searchTerms, $caseInsensitive, false, 'list-equals'); |
||
199 | |||
200 | if($command instanceof Mailcode_Commands_Command_If_ListEquals) |
||
201 | { |
||
202 | return $command; |
||
203 | } |
||
204 | |||
205 | throw $this->instantiator->exceptionUnexpectedType('IfListEquals', $command); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @param string $variable |
||
210 | * @param string[] $searchTerms |
||
211 | * @param bool $caseInsensitive |
||
212 | * @param bool $regexEnabled |
||
213 | * @return Mailcode_Commands_Command_If_ListNotContains |
||
214 | * @throws Mailcode_Factory_Exception |
||
215 | */ |
||
216 | public function listNotContains(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_If_ListNotContains |
||
217 | { |
||
218 | $command = $this->instantiator->buildIfListNotContains('If', $variable, $searchTerms, $caseInsensitive, $regexEnabled); |
||
219 | |||
220 | if($command instanceof Mailcode_Commands_Command_If_ListNotContains) |
||
221 | { |
||
222 | return $command; |
||
223 | } |
||
224 | |||
225 | throw $this->instantiator->exceptionUnexpectedType('IfNotContains', $command); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @param string $variable |
||
230 | * @param string[] $searchTerms |
||
231 | * @param bool $caseInsensitive |
||
232 | * @param bool $regexEnabled |
||
233 | * @return Mailcode_Commands_Command_If_ListBeginsWith |
||
234 | * @throws Mailcode_Factory_Exception |
||
235 | */ |
||
236 | public function listBeginsWith(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_If_ListBeginsWith |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @param string $variable |
||
250 | * @param string[] $searchTerms |
||
251 | * @param bool $caseInsensitive |
||
252 | * @param bool $regexEnabled |
||
253 | * @return Mailcode_Commands_Command_If_ListEndsWith |
||
254 | * @throws Mailcode_Factory_Exception |
||
255 | */ |
||
256 | public function listEndsWith(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_If_ListEndsWith |
||
266 | } |
||
267 | |||
268 | public function beginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_BeginsWith |
||
269 | { |
||
270 | $command = $this->instantiator->buildIfBeginsWith('If', $variable, $search, $caseInsensitive); |
||
271 | |||
272 | if($command instanceof Mailcode_Commands_Command_If_BeginsWith) |
||
273 | { |
||
274 | return $command; |
||
275 | } |
||
276 | |||
277 | throw $this->instantiator->exceptionUnexpectedType('IfBeginsWith', $command); |
||
278 | } |
||
279 | |||
280 | public function endsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_If_EndsWith |
||
281 | { |
||
282 | $command = $this->instantiator->buildIfEndsWith('If', $variable, $search, $caseInsensitive); |
||
283 | |||
284 | if($command instanceof Mailcode_Commands_Command_If_EndsWith) |
||
285 | { |
||
286 | return $command; |
||
287 | } |
||
288 | |||
289 | throw $this->instantiator->exceptionUnexpectedType('IfEndsWith', $command); |
||
290 | } |
||
291 | |||
292 | public function biggerThan(string $variable, string $value) : Mailcode_Commands_Command_If_BiggerThan |
||
302 | } |
||
303 | |||
304 | public function smallerThan(string $variable, string $value) : Mailcode_Commands_Command_If_SmallerThan |
||
314 | } |
||
315 | |||
316 | public function varEqualsNumber(string $variable, string $value) : Mailcode_Commands_Command_If_EqualsNumber |
||
326 | } |
||
327 | } |
||
328 |