Complex classes like InputParam 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 InputParam, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | abstract class InputParam implements ParamInterface |
||
11 | { |
||
12 | const TYPE_POST = 'POST'; |
||
13 | const TYPE_GET = 'GET'; |
||
14 | const TYPE_PUT = 'PUT'; |
||
15 | const TYPE_FILE = 'FILE'; |
||
16 | const TYPE_COOKIE = 'COOKIE'; |
||
17 | const TYPE_POST_RAW = 'POST_RAW'; |
||
18 | const TYPE_POST_JSON = 'POST_JSON'; |
||
19 | |||
20 | const OPTIONAL = false; |
||
21 | const REQUIRED = true; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $type; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $key; |
||
28 | |||
29 | /** @var bool */ |
||
30 | protected $required = self::OPTIONAL; |
||
31 | |||
32 | /** @var array|null */ |
||
33 | protected $availableValues = null; |
||
34 | |||
35 | /** @var bool */ |
||
36 | protected $multi = false; |
||
37 | |||
38 | /** @var string */ |
||
39 | protected $description = ''; |
||
40 | |||
41 | /** @var mixed */ |
||
42 | protected $default; |
||
43 | |||
44 | /** @var mixed */ |
||
45 | protected $example; |
||
46 | |||
47 | protected $errors = []; |
||
48 | |||
49 | 69 | public function __construct(string $key) |
|
53 | |||
54 | 45 | public function setRequired(): self |
|
59 | |||
60 | 24 | public function setAvailableValues(array $availableValues): self |
|
65 | |||
66 | 12 | public function setMulti(): self |
|
71 | |||
72 | 21 | public function getType(): string |
|
76 | |||
77 | 33 | public function getKey(): string |
|
81 | |||
82 | 21 | public function isRequired(): bool |
|
86 | |||
87 | 12 | public function getAvailableValues(): ?array |
|
91 | |||
92 | 42 | public function isMulti(): bool |
|
96 | |||
97 | 3 | public function setDescription(string $description): self |
|
102 | |||
103 | 3 | public function getDescription(): string |
|
107 | |||
108 | /** |
||
109 | * @param mixed $default |
||
110 | * @return self |
||
111 | */ |
||
112 | 3 | public function setDefault($default): self |
|
117 | |||
118 | /** |
||
119 | * @return mixed |
||
120 | */ |
||
121 | 12 | public function getDefault() |
|
125 | |||
126 | /** |
||
127 | * @param mixed $example |
||
128 | * @return self |
||
129 | */ |
||
130 | 3 | public function setExample($example): self |
|
135 | |||
136 | /** |
||
137 | * @return mixed |
||
138 | */ |
||
139 | 12 | public function getExample() |
|
143 | |||
144 | 12 | public function updateConsoleForm(Form $form): void |
|
163 | |||
164 | 6 | protected function addFormInput(Form $form, string $key): BaseControl |
|
172 | |||
173 | 12 | protected function getLabel(): string |
|
177 | |||
178 | 12 | protected function getParamLabel(): string |
|
187 | |||
188 | /** |
||
189 | * Check if actual value from environment is valid |
||
190 | */ |
||
191 | 18 | public function isValid(): bool |
|
215 | |||
216 | 9 | public function getErrors(): array |
|
220 | } |
||
221 |