Complex classes like ParamDefinition 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 ParamDefinition, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class ParamDefinition implements IParamDefinition { |
||
|
|||
27 | |||
28 | /** |
||
29 | * Indicates whether parameters that are provided more then once should be accepted, |
||
30 | * and use the first provided value, or not, and generate an error. |
||
31 | * |
||
32 | * @since 1.0 |
||
33 | * |
||
34 | * @var boolean |
||
35 | */ |
||
36 | public static $acceptOverriding = false; |
||
37 | |||
38 | /** |
||
39 | * Indicates whether parameters not found in the criteria list |
||
40 | * should be stored in case they are not accepted. The default is false. |
||
41 | * |
||
42 | * @since 1.0 |
||
43 | * |
||
44 | * @var boolean |
||
45 | */ |
||
46 | public static $accumulateParameterErrors = false; |
||
47 | |||
48 | /** |
||
49 | * Indicates if the parameter value should trimmed during the clean process. |
||
50 | * |
||
51 | * @since 1.0 |
||
52 | * |
||
53 | * @var boolean|null |
||
54 | */ |
||
55 | protected $trimValue = null; |
||
56 | |||
57 | /** |
||
58 | * Indicates if the parameter manipulations should be applied to the default value. |
||
59 | * |
||
60 | * @since 1.0 |
||
61 | * |
||
62 | * @var boolean |
||
63 | */ |
||
64 | protected $applyManipulationsToDefault = true; |
||
65 | |||
66 | /** |
||
67 | * Dependency list containing parameters that need to be handled before this one. |
||
68 | * |
||
69 | * @since 1.0 |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $dependencies = []; |
||
74 | |||
75 | /** |
||
76 | * The default value for the parameter, or null when the parameter is required. |
||
77 | * |
||
78 | * @since 1.0 |
||
79 | * |
||
80 | * @var mixed |
||
81 | */ |
||
82 | protected $default; |
||
83 | |||
84 | /** |
||
85 | * The main name of the parameter. |
||
86 | * |
||
87 | * @since 1.0 |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $name; |
||
92 | |||
93 | /** |
||
94 | * @since 1.0 |
||
95 | * @var boolean |
||
96 | */ |
||
97 | protected $isList; |
||
98 | |||
99 | /** |
||
100 | * @since 1.0 |
||
101 | * @var string |
||
102 | */ |
||
103 | protected $delimiter = ','; |
||
104 | |||
105 | /** |
||
106 | * List of aliases for the parameter name. |
||
107 | * |
||
108 | * @since 1.0 |
||
109 | * |
||
110 | * @var array |
||
111 | */ |
||
112 | protected $aliases = []; |
||
113 | |||
114 | /** |
||
115 | * A message that acts as description for the parameter or false when there is none. |
||
116 | * Can be obtained via getMessage and set via setMessage. |
||
117 | * |
||
118 | * @since 1.0 |
||
119 | * |
||
120 | * @var string |
||
121 | */ |
||
122 | protected $message = 'validator-message-nodesc'; |
||
123 | |||
124 | /** |
||
125 | * Original array definition of the parameter |
||
126 | * |
||
127 | * @since 1.0 |
||
128 | * |
||
129 | * @var array |
||
130 | */ |
||
131 | protected $options = []; |
||
132 | |||
133 | /** |
||
134 | * @since 1.0 |
||
135 | * |
||
136 | * @var ValueParser|null |
||
137 | */ |
||
138 | protected $parser = null; |
||
139 | |||
140 | /** |
||
141 | * @since 1.0 |
||
142 | * |
||
143 | * @var ValueValidator|null |
||
144 | */ |
||
145 | protected $validator = null; |
||
146 | |||
147 | /** |
||
148 | * @since 0.1 |
||
149 | * |
||
150 | * @var callable|null |
||
151 | */ |
||
152 | protected $validationFunction = null; |
||
153 | |||
154 | /** |
||
155 | * @since 0.1 |
||
156 | * |
||
157 | * @var string |
||
158 | */ |
||
159 | protected $type; |
||
160 | |||
161 | /** |
||
162 | * Constructor. |
||
163 | * |
||
164 | * @since 1.0 |
||
165 | * |
||
166 | * @param string $type |
||
167 | * @param string $name |
||
168 | * @param mixed $default Use null for no default (which makes the parameter required) |
||
169 | * @param string $message |
||
170 | * @param boolean $isList |
||
171 | */ |
||
172 | 36 | public function __construct( $type, $name, $default = null, $message = null, $isList = false ) { |
|
181 | |||
182 | /** |
||
183 | * Allows deriving classed to do additional stuff on instance construction |
||
184 | * without having to get and pass all the constructor arguments. |
||
185 | * |
||
186 | * @since 1.0 |
||
187 | */ |
||
188 | 36 | protected function postConstruct() { |
|
191 | |||
192 | /** |
||
193 | * @see IParamDefinition::trimDuringClean |
||
194 | * |
||
195 | * @since 1.0 |
||
196 | * |
||
197 | * @return boolean|null |
||
198 | */ |
||
199 | 64 | public function trimDuringClean() { |
|
202 | |||
203 | /** |
||
204 | * @see IParamDefinition::getAliases |
||
205 | * |
||
206 | * @since 1.0 |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function getAliases() { |
||
213 | |||
214 | /** |
||
215 | * @see IParamDefinition::hasAlias |
||
216 | * |
||
217 | * @since 1.0 |
||
218 | * |
||
219 | * @param string $alias |
||
220 | * |
||
221 | * @return boolean |
||
222 | */ |
||
223 | public function hasAlias( $alias ) { |
||
226 | |||
227 | /** |
||
228 | * @see IParamDefinition::hasDependency |
||
229 | * |
||
230 | * @since 1.0 |
||
231 | * |
||
232 | * @param string $dependency |
||
233 | * |
||
234 | * @return boolean |
||
235 | */ |
||
236 | public function hasDependency( $dependency ) { |
||
239 | |||
240 | /** |
||
241 | * Returns the list of allowed values, or false if there is no such restriction. |
||
242 | * |
||
243 | * @since 1.0 |
||
244 | * |
||
245 | * @return array|boolean false |
||
246 | */ |
||
247 | public function getAllowedValues() { |
||
264 | |||
265 | /** |
||
266 | * @see IParamDefinition::setDefault |
||
267 | * |
||
268 | * @since 1.0 |
||
269 | * |
||
270 | * @param mixed $default |
||
271 | * @param boolean $manipulate Should the default be manipulated or not? Since 0.4.6. |
||
272 | */ |
||
273 | public function setDefault( $default, $manipulate = true ) { |
||
277 | |||
278 | /** |
||
279 | * @see IParamDefinition::getDefault |
||
280 | * |
||
281 | * @since 1.0 |
||
282 | * |
||
283 | * @return mixed |
||
284 | */ |
||
285 | 1 | public function getDefault() { |
|
288 | |||
289 | /** |
||
290 | * @see IParamDefinition::getMessage |
||
291 | * |
||
292 | * @since 1.0 |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public function getMessage() { |
||
299 | |||
300 | /** |
||
301 | * @see IParamDefinition::setMessage |
||
302 | * |
||
303 | * @since 1.0 |
||
304 | * |
||
305 | * @param string $message |
||
306 | */ |
||
307 | public function setMessage( $message ) { |
||
310 | |||
311 | /** |
||
312 | * @see IParamDefinition::setDoManipulationOfDefault |
||
313 | * |
||
314 | * @since 1.0 |
||
315 | * |
||
316 | * @param boolean $doOrDoNotThereIsNoTry |
||
317 | */ |
||
318 | public function setDoManipulationOfDefault( $doOrDoNotThereIsNoTry ) { |
||
321 | |||
322 | /** |
||
323 | * @see IParamDefinition::shouldManipulateDefault |
||
324 | * |
||
325 | * @since 1.0 |
||
326 | * |
||
327 | * @return boolean |
||
328 | */ |
||
329 | 56 | public function shouldManipulateDefault() { |
|
332 | |||
333 | /** |
||
334 | * @see IParamDefinition::addAliases |
||
335 | * |
||
336 | * @since 1.0 |
||
337 | * |
||
338 | * @param mixed $aliases string or array of string |
||
339 | */ |
||
340 | public function addAliases( $aliases ) { |
||
344 | |||
345 | /** |
||
346 | * @see IParamDefinition::addDependencies |
||
347 | * |
||
348 | * @since 1.0 |
||
349 | * |
||
350 | * @param mixed $dependencies string or array of string |
||
351 | */ |
||
352 | public function addDependencies( $dependencies ) { |
||
356 | |||
357 | /** |
||
358 | * @see IParamDefinition::getName |
||
359 | * |
||
360 | * @since 1.0 |
||
361 | * |
||
362 | * @return string |
||
363 | */ |
||
364 | 68 | public function getName() { |
|
367 | |||
368 | /** |
||
369 | * Returns a message key for a message describing the parameter type. |
||
370 | * |
||
371 | * @since 1.0 |
||
372 | * |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getTypeMessage() { |
||
384 | |||
385 | /** |
||
386 | * @see IParamDefinition::getDependencies |
||
387 | * |
||
388 | * @since 1.0 |
||
389 | * |
||
390 | * @return array |
||
391 | */ |
||
392 | public function getDependencies() { |
||
395 | |||
396 | /** |
||
397 | * @see IParamDefinition::isRequired |
||
398 | * |
||
399 | * @since 1.0 |
||
400 | * |
||
401 | * @return boolean |
||
402 | */ |
||
403 | 21 | public function isRequired() { |
|
406 | |||
407 | /** |
||
408 | * @see IParamDefinition::isList |
||
409 | * |
||
410 | * @since 1.0 |
||
411 | * |
||
412 | * @return boolean |
||
413 | */ |
||
414 | 64 | public function isList() { |
|
417 | |||
418 | /** |
||
419 | * @see IParamDefinition::getDelimiter |
||
420 | * |
||
421 | * @since 1.0 |
||
422 | * |
||
423 | * @return string |
||
424 | */ |
||
425 | public function getDelimiter() { |
||
428 | |||
429 | /** |
||
430 | * @see IParamDefinition::setDelimiter |
||
431 | * |
||
432 | * @since 1.0 |
||
433 | * |
||
434 | * @param $delimiter string |
||
435 | */ |
||
436 | public function setDelimiter( $delimiter ) { |
||
439 | |||
440 | /** |
||
441 | * @see IParamDefinition::setArrayValues |
||
442 | * |
||
443 | * @since 1.0 |
||
444 | * |
||
445 | * @param array $param |
||
446 | */ |
||
447 | 36 | public function setArrayValues( array $param ) { |
|
470 | |||
471 | /** |
||
472 | * @see IParamDefinition::format |
||
473 | * |
||
474 | * @since 1.0 |
||
475 | * @deprecated |
||
476 | * |
||
477 | * @param IParam $param |
||
478 | * @param IParamDefinition[] $definitions |
||
479 | * @param IParam[] $params |
||
480 | */ |
||
481 | 56 | public function format( IParam $param, array &$definitions, array $params ) { |
|
507 | |||
508 | /** |
||
509 | * Formats the parameters values to their final result. |
||
510 | * |
||
511 | * @since 1.0 |
||
512 | * @deprecated |
||
513 | * |
||
514 | * @param $param IParam |
||
515 | * @param $definitions array of IParamDefinition |
||
516 | * @param $params array of IParam |
||
517 | */ |
||
518 | protected function formatList( IParam $param, array &$definitions, array $params ) { |
||
521 | |||
522 | /** |
||
523 | * Formats the parameter value to it's final result. |
||
524 | * |
||
525 | * @since 1.0 |
||
526 | * @deprecated |
||
527 | * |
||
528 | * @param mixed $value |
||
529 | * @param IParam $param |
||
530 | * @param IParamDefinition[] $definitions |
||
531 | * @param IParam[] $params |
||
532 | * |
||
533 | * @return mixed |
||
534 | */ |
||
535 | 42 | protected function formatValue( $value, IParam $param, array &$definitions, array $params ) { |
|
539 | |||
540 | /** |
||
541 | * Returns a cleaned version of the list of parameter definitions. |
||
542 | * This includes having converted all supported definition types to |
||
543 | * ParamDefinition classes and having all keys set to the names of the |
||
544 | * corresponding parameters. |
||
545 | * |
||
546 | * @since 1.0 |
||
547 | * |
||
548 | * @param IParamDefinition[] $definitions |
||
549 | * |
||
550 | * @return IParamDefinition[] |
||
551 | * @throws Exception |
||
552 | */ |
||
553 | 56 | public static function getCleanDefinitions( array $definitions ) { |
|
574 | |||
575 | /** |
||
576 | * @see IParamDefinition::getType |
||
577 | * |
||
578 | * @since 1.0 |
||
579 | * |
||
580 | * @return string |
||
581 | */ |
||
582 | 80 | public function getType() { |
|
585 | |||
586 | /** |
||
587 | * @see IParamDefinition::getValueParser |
||
588 | * |
||
589 | * @since 1.0 |
||
590 | * |
||
591 | * @return ValueParser |
||
592 | */ |
||
593 | 64 | public function getValueParser() { |
|
600 | |||
601 | /** |
||
602 | * @see IParamDefinition::getValueValidator |
||
603 | * |
||
604 | * @since 1.0 |
||
605 | * |
||
606 | * @return ValueValidator |
||
607 | */ |
||
608 | 64 | public function getValueValidator() { |
|
615 | |||
616 | /** |
||
617 | * @see IParamDefinition::setValueParser |
||
618 | * |
||
619 | * @since 1.0 |
||
620 | * |
||
621 | * @param ValueParser $parser |
||
622 | */ |
||
623 | public function setValueParser( ValueParser $parser ) { |
||
626 | |||
627 | /** |
||
628 | * @see IParamDefinition::setValueValidator |
||
629 | * |
||
630 | * @since 1.0 |
||
631 | * |
||
632 | * @param ValueValidator $validator |
||
633 | */ |
||
634 | 36 | public function setValueValidator( ValueValidator $validator ) { |
|
637 | |||
638 | /** |
||
639 | * @see IParamDefinition::setValidationCallback |
||
640 | * |
||
641 | * @since 1.0 |
||
642 | * |
||
643 | * @param callable $validationFunction |
||
644 | */ |
||
645 | 36 | public function setValidationCallback( /* callable */ $validationFunction ) { |
|
648 | |||
649 | /** |
||
650 | * @see IParamDefinition::getValidationCallback |
||
651 | * |
||
652 | * @since 1.0 |
||
653 | * |
||
654 | * @return callable|null |
||
655 | */ |
||
656 | 64 | public function getValidationCallback() { |
|
659 | |||
660 | /** |
||
661 | * @since 0.1 |
||
662 | * |
||
663 | * @return array |
||
664 | */ |
||
665 | 64 | public function getOptions() { |
|
668 | |||
669 | } |
||
670 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.