| Total Complexity | 44 |
| Total Lines | 317 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Mailcode_Factory_CommandSets_Set_ElseIf 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_ElseIf, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Mailcode_Factory_CommandSets_Set_ElseIf extends Mailcode_Factory_CommandSets_IfBase |
||
| 22 | { |
||
| 23 | public function elseIf(string $condition, string $type='') : Mailcode_Commands_Command_ElseIf |
||
| 33 | } |
||
| 34 | |||
| 35 | public function var(string $variable, string $operand, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 36 | { |
||
| 37 | $command = $this->instantiator->buildIfVar('ElseIf', $variable, $operand, $value, $quoteValue, $insensitive); |
||
| 38 | |||
| 39 | if($command instanceof Mailcode_Commands_Command_ElseIf_Variable) |
||
| 40 | { |
||
| 41 | return $command; |
||
| 42 | } |
||
| 43 | |||
| 44 | throw $this->instantiator->exceptionUnexpectedType('ElseIfVariable', $command); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function varString(string $variable, string $operand, string $value, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 48 | { |
||
| 49 | $command = $this->instantiator->buildIfVar('ElseIf', $variable, $operand, $value, true, $insensitive); |
||
| 50 | |||
| 51 | if($command instanceof Mailcode_Commands_Command_ElseIf_Variable) |
||
| 52 | { |
||
| 53 | return $command; |
||
| 54 | } |
||
| 55 | |||
| 56 | throw $this->instantiator->exceptionUnexpectedType('ElseIfVarString', $command); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function varEquals(string $variable, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 69 | } |
||
| 70 | |||
| 71 | public function varEqualsString(string $variable, string $value, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 81 | } |
||
| 82 | |||
| 83 | public function varEqualsNumber(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_EqualsNumber |
||
| 84 | { |
||
| 85 | $command = $this->instantiator->buildIfEquals('ElseIf', $variable, $value); |
||
| 86 | |||
| 87 | if($command instanceof Mailcode_Commands_Command_ElseIf_EqualsNumber) |
||
| 88 | { |
||
| 89 | return $command; |
||
| 90 | } |
||
| 91 | |||
| 92 | throw $this->instantiator->exceptionUnexpectedType('IfEqualsNumber', $command); |
||
| 93 | } |
||
| 94 | |||
| 95 | public function varNotEquals(string $variable, string $value, bool $quoteValue=false, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 96 | { |
||
| 97 | $command = $this->instantiator->buildIfVar('ElseIf', $variable, '!=', $value, $quoteValue, $insensitive); |
||
| 98 | |||
| 99 | if($command instanceof Mailcode_Commands_Command_ElseIf_Variable) |
||
| 100 | { |
||
| 101 | return $command; |
||
| 102 | } |
||
| 103 | |||
| 104 | throw $this->instantiator->exceptionUnexpectedType('ElseIfVarNotEquals', $command); |
||
| 105 | } |
||
| 106 | |||
| 107 | public function varNotEqualsString(string $variable, string $value, bool $insensitive=false) : Mailcode_Commands_Command_ElseIf_Variable |
||
| 108 | { |
||
| 109 | $command = $this->instantiator->buildIfVar('ElseIf', $variable, '!=', $value, true, $insensitive); |
||
| 110 | |||
| 111 | if($command instanceof Mailcode_Commands_Command_ElseIf_Variable) |
||
| 112 | { |
||
| 113 | return $command; |
||
| 114 | } |
||
| 115 | |||
| 116 | throw $this->instantiator->exceptionUnexpectedType('ElseIfVarNotEqualsString', $command); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param string $variable |
||
| 121 | * @param string[] $searchTerms |
||
| 122 | * @param bool $caseInsensitive |
||
| 123 | * @return Mailcode_Commands_Command_ElseIf_Contains |
||
| 124 | * @throws Mailcode_Factory_Exception |
||
| 125 | */ |
||
| 126 | public function contains(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_Contains |
||
| 127 | { |
||
| 128 | $command = $this->instantiator->buildIfContains('ElseIf', $variable, $searchTerms, $caseInsensitive); |
||
| 129 | |||
| 130 | if($command instanceof Mailcode_Commands_Command_ElseIf_Contains) |
||
| 131 | { |
||
| 132 | return $command; |
||
| 133 | } |
||
| 134 | |||
| 135 | throw $this->instantiator->exceptionUnexpectedType('ElseIfContains', $command); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param string $variable |
||
| 140 | * @param string[] $searchTerms |
||
| 141 | * @param bool $caseInsensitive |
||
| 142 | * @return Mailcode_Commands_Command_ElseIf_NotContains |
||
| 143 | * @throws Mailcode_Factory_Exception |
||
| 144 | */ |
||
| 145 | public function notContains(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_NotContains |
||
| 146 | { |
||
| 147 | $command = $this->instantiator->buildIfNotContains('ElseIf', $variable, $searchTerms, $caseInsensitive); |
||
| 148 | |||
| 149 | if($command instanceof Mailcode_Commands_Command_ElseIf_NotContains) |
||
| 150 | { |
||
| 151 | return $command; |
||
| 152 | } |
||
| 153 | |||
| 154 | throw $this->instantiator->exceptionUnexpectedType('ElseIfNotContains', $command); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $variable |
||
| 159 | * @param string[] $searchTerms |
||
| 160 | * @param bool $caseInsensitive |
||
| 161 | * @param bool $regexEnabled |
||
| 162 | * @return Mailcode_Commands_Command_ElseIf_ListContains |
||
| 163 | * @throws Mailcode_Factory_Exception |
||
| 164 | */ |
||
| 165 | public function listContains(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_ElseIf_ListContains |
||
| 166 | { |
||
| 167 | $command = $this->instantiator->buildIfListContains('ElseIf', $variable, $searchTerms, $caseInsensitive, $regexEnabled); |
||
| 168 | |||
| 169 | if($command instanceof Mailcode_Commands_Command_ElseIf_ListContains) |
||
| 170 | { |
||
| 171 | return $command; |
||
| 172 | } |
||
| 173 | |||
| 174 | throw $this->instantiator->exceptionUnexpectedType('ElseIfListContains', $command); |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $variable |
||
| 179 | * @param string[] $searchTerms |
||
| 180 | * @param bool $caseInsensitive |
||
| 181 | * @return Mailcode_Commands_Command_ElseIf_ListEquals |
||
| 182 | * @throws Mailcode_Factory_Exception |
||
| 183 | */ |
||
| 184 | public function listEquals(string $variable, array $searchTerms, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_ListEquals |
||
| 185 | { |
||
| 186 | $command = $this->instantiator->buildIfListContains('ElseIf', $variable, $searchTerms, $caseInsensitive, false, 'list-equals'); |
||
| 187 | |||
| 188 | if($command instanceof Mailcode_Commands_Command_ElseIf_ListEquals) |
||
| 189 | { |
||
| 190 | return $command; |
||
| 191 | } |
||
| 192 | |||
| 193 | throw $this->instantiator->exceptionUnexpectedType('ElseIfListEquals', $command); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $variable |
||
| 198 | * @param string[] $searchTerms |
||
| 199 | * @param bool $caseInsensitive |
||
| 200 | * @param bool $regexEnabled |
||
| 201 | * @return Mailcode_Commands_Command_ElseIf_ListNotContains |
||
| 202 | * @throws Mailcode_Factory_Exception |
||
| 203 | */ |
||
| 204 | public function listNotContains(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_ElseIf_ListNotContains |
||
| 205 | { |
||
| 206 | $command = $this->instantiator->buildIfListNotContains('ElseIf', $variable, $searchTerms, $caseInsensitive, $regexEnabled); |
||
| 207 | |||
| 208 | if($command instanceof Mailcode_Commands_Command_ElseIf_ListNotContains) |
||
| 209 | { |
||
| 210 | return $command; |
||
| 211 | } |
||
| 212 | |||
| 213 | throw $this->instantiator->exceptionUnexpectedType('ElseIfListNotContains', $command); |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param string $variable |
||
| 218 | * @param string[] $searchTerms |
||
| 219 | * @param bool $caseInsensitive |
||
| 220 | * @param bool $regexEnabled |
||
| 221 | * @return Mailcode_Commands_Command_ElseIf_ListBeginsWith |
||
| 222 | * @throws Mailcode_Factory_Exception |
||
| 223 | */ |
||
| 224 | public function listBeginsWith(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_ElseIf_ListBeginsWith |
||
| 225 | { |
||
| 226 | $command = $this->instantiator->buildIfListContains('ElseIf', $variable, $searchTerms, $caseInsensitive, $regexEnabled, 'list-begins-with'); |
||
| 227 | |||
| 228 | if($command instanceof Mailcode_Commands_Command_ElseIf_ListBeginsWith) |
||
| 229 | { |
||
| 230 | return $command; |
||
| 231 | } |
||
| 232 | |||
| 233 | throw $this->instantiator->exceptionUnexpectedType('ElseIfListBeginsWith', $command); |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param string $variable |
||
| 238 | * @param string[] $searchTerms |
||
| 239 | * @param bool $caseInsensitive |
||
| 240 | * @param bool $regexEnabled |
||
| 241 | * @return Mailcode_Commands_Command_ElseIf_ListEndsWith |
||
| 242 | * @throws Mailcode_Factory_Exception |
||
| 243 | */ |
||
| 244 | public function listEndsWith(string $variable, array $searchTerms, bool $caseInsensitive=false, bool $regexEnabled=false) : Mailcode_Commands_Command_ElseIf_ListEndsWith |
||
| 245 | { |
||
| 246 | $command = $this->instantiator->buildIfListContains('ElseIf', $variable, $searchTerms, $caseInsensitive, $regexEnabled, 'list-ends-with'); |
||
| 247 | |||
| 248 | if($command instanceof Mailcode_Commands_Command_ElseIf_ListEndsWith) |
||
| 249 | { |
||
| 250 | return $command; |
||
| 251 | } |
||
| 252 | |||
| 253 | throw $this->instantiator->exceptionUnexpectedType('ElseIfListEndsWith', $command); |
||
| 254 | } |
||
| 255 | |||
| 256 | public function beginsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_BeginsWith |
||
| 266 | } |
||
| 267 | |||
| 268 | public function endsWith(string $variable, string $search, bool $caseInsensitive=false) : Mailcode_Commands_Command_ElseIf_EndsWith |
||
| 269 | { |
||
| 270 | $command = $this->instantiator->buildIfEndsWith('ElseIf', $variable, $search, $caseInsensitive); |
||
| 271 | |||
| 272 | if($command instanceof Mailcode_Commands_Command_ElseIf_EndsWith) |
||
| 273 | { |
||
| 274 | return $command; |
||
| 275 | } |
||
| 276 | |||
| 277 | throw $this->instantiator->exceptionUnexpectedType('ElseIfEndsWith', $command); |
||
| 278 | } |
||
| 279 | |||
| 280 | public function empty(string $variable) : Mailcode_Commands_Command_ElseIf_Empty |
||
| 281 | { |
||
| 282 | $command = $this->instantiator->buildIfEmpty('ElseIf', $variable); |
||
| 283 | |||
| 284 | if($command instanceof Mailcode_Commands_Command_ElseIf_Empty) |
||
| 285 | { |
||
| 286 | return $command; |
||
| 287 | } |
||
| 288 | |||
| 289 | throw $this->instantiator->exceptionUnexpectedType('ElseIfEmpty', $command); |
||
| 290 | } |
||
| 291 | |||
| 292 | public function notEmpty(string $variable) : Mailcode_Commands_Command_ElseIf_NotEmpty |
||
| 293 | { |
||
| 294 | $command = $this->instantiator->buildIfNotEmpty('ElseIf', $variable); |
||
| 295 | |||
| 296 | if($command instanceof Mailcode_Commands_Command_ElseIf_NotEmpty) |
||
| 297 | { |
||
| 298 | return $command; |
||
| 299 | } |
||
| 300 | |||
| 301 | throw $this->instantiator->exceptionUnexpectedType('ElseIfNotEmpty', $command); |
||
| 302 | } |
||
| 303 | |||
| 304 | public function biggerThan(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_BiggerThan |
||
| 314 | } |
||
| 315 | |||
| 316 | public function smallerThan(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_SmallerThan |
||
| 317 | { |
||
| 326 | } |
||
| 327 | |||
| 328 | public function equalsNumber(string $variable, string $value) : Mailcode_Commands_Command_ElseIf_EqualsNumber |
||
| 338 | } |
||
| 339 | } |
||
| 340 |