Complex classes like ContainerConfig 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 ContainerConfig, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class ContainerConfig |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | protected $id; |
||
11 | /** |
||
12 | * @var string[] |
||
13 | */ |
||
14 | protected $names; |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $image; |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $command; |
||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $created; |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $status; |
||
31 | /** |
||
32 | * @var Port[] |
||
33 | */ |
||
34 | protected $ports; |
||
35 | /** |
||
36 | * @var string[] |
||
37 | */ |
||
38 | protected $labels; |
||
39 | /** |
||
40 | * @var int |
||
41 | */ |
||
42 | protected $sizeRw; |
||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $sizeRootFs; |
||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | protected $hostname; |
||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $domainname; |
||
55 | /** |
||
56 | * @var int |
||
57 | */ |
||
58 | protected $user; |
||
59 | /** |
||
60 | * @var bool |
||
61 | */ |
||
62 | protected $attachStdin; |
||
63 | /** |
||
64 | * @var bool |
||
65 | */ |
||
66 | protected $attachStdout; |
||
67 | /** |
||
68 | * @var bool |
||
69 | */ |
||
70 | protected $attachStderr; |
||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | protected $tty; |
||
75 | /** |
||
76 | * @var bool |
||
77 | */ |
||
78 | protected $openStdin; |
||
79 | /** |
||
80 | * @var bool |
||
81 | */ |
||
82 | protected $stdinOnce; |
||
83 | /** |
||
84 | * @var string[] |
||
85 | */ |
||
86 | protected $env; |
||
87 | /** |
||
88 | * @var string[]|string |
||
89 | */ |
||
90 | protected $cmd; |
||
91 | /** |
||
92 | * @var string[]|string |
||
93 | */ |
||
94 | protected $entrypoint; |
||
95 | /** |
||
96 | * @var Mount[] |
||
97 | */ |
||
98 | protected $mounts; |
||
99 | /** |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $workingDir; |
||
103 | /** |
||
104 | * @var bool |
||
105 | */ |
||
106 | protected $networkDisabled; |
||
107 | /** |
||
108 | * @var string |
||
109 | */ |
||
110 | protected $macAddress; |
||
111 | /** |
||
112 | * @var mixed[] |
||
113 | */ |
||
114 | protected $exposedPorts; |
||
115 | /** |
||
116 | * @var HostConfig |
||
117 | */ |
||
118 | protected $hostConfig; |
||
119 | |||
120 | /** |
||
121 | * @return string |
||
122 | */ |
||
123 | public function getId() |
||
127 | |||
128 | /** |
||
129 | * @param string $id |
||
130 | * |
||
131 | * @return self |
||
132 | */ |
||
133 | public function setId($id = null) |
||
139 | |||
140 | /** |
||
141 | * @return string[] |
||
142 | */ |
||
143 | public function getNames() |
||
147 | |||
148 | /** |
||
149 | * @param string[] $names |
||
150 | * |
||
151 | * @return self |
||
152 | */ |
||
153 | public function setNames(array $names = null) |
||
159 | |||
160 | /** |
||
161 | * @return string |
||
162 | */ |
||
163 | public function getImage() |
||
167 | |||
168 | /** |
||
169 | * @param string $image |
||
170 | * |
||
171 | * @return self |
||
172 | */ |
||
173 | public function setImage($image = null) |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getCommand() |
||
187 | |||
188 | /** |
||
189 | * @param string $command |
||
190 | * |
||
191 | * @return self |
||
192 | */ |
||
193 | public function setCommand($command = null) |
||
199 | |||
200 | /** |
||
201 | * @return int |
||
202 | */ |
||
203 | public function getCreated() |
||
207 | |||
208 | /** |
||
209 | * @param int $created |
||
210 | * |
||
211 | * @return self |
||
212 | */ |
||
213 | public function setCreated($created = null) |
||
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | public function getStatus() |
||
227 | |||
228 | /** |
||
229 | * @param string $status |
||
230 | * |
||
231 | * @return self |
||
232 | */ |
||
233 | public function setStatus($status = null) |
||
239 | |||
240 | /** |
||
241 | * @return Port[] |
||
242 | */ |
||
243 | public function getPorts() |
||
247 | |||
248 | /** |
||
249 | * @param Port[] $ports |
||
250 | * |
||
251 | * @return self |
||
252 | */ |
||
253 | public function setPorts(array $ports = null) |
||
259 | |||
260 | /** |
||
261 | * @return string[] |
||
262 | */ |
||
263 | public function getLabels() |
||
267 | |||
268 | /** |
||
269 | * @param string[] $labels |
||
270 | * |
||
271 | * @return self |
||
272 | */ |
||
273 | public function setLabels(\ArrayObject $labels = null) |
||
279 | |||
280 | /** |
||
281 | * @return int |
||
282 | */ |
||
283 | public function getSizeRw() |
||
287 | |||
288 | /** |
||
289 | * @param int $sizeRw |
||
290 | * |
||
291 | * @return self |
||
292 | */ |
||
293 | public function setSizeRw($sizeRw = null) |
||
299 | |||
300 | /** |
||
301 | * @return int |
||
302 | */ |
||
303 | public function getSizeRootFs() |
||
307 | |||
308 | /** |
||
309 | * @param int $sizeRootFs |
||
310 | * |
||
311 | * @return self |
||
312 | */ |
||
313 | public function setSizeRootFs($sizeRootFs = null) |
||
319 | |||
320 | /** |
||
321 | * @return int |
||
322 | */ |
||
323 | public function getHostname() |
||
327 | |||
328 | /** |
||
329 | * @param int $hostname |
||
330 | * |
||
331 | * @return self |
||
332 | */ |
||
333 | public function setHostname($hostname = null) |
||
339 | |||
340 | /** |
||
341 | * @return int |
||
342 | */ |
||
343 | public function getDomainname() |
||
347 | |||
348 | /** |
||
349 | * @param int $domainname |
||
350 | * |
||
351 | * @return self |
||
352 | */ |
||
353 | public function setDomainname($domainname = null) |
||
359 | |||
360 | /** |
||
361 | * @return int |
||
362 | */ |
||
363 | public function getUser() |
||
367 | |||
368 | /** |
||
369 | * @param int $user |
||
370 | * |
||
371 | * @return self |
||
372 | */ |
||
373 | public function setUser($user = null) |
||
379 | |||
380 | /** |
||
381 | * @return bool |
||
382 | */ |
||
383 | public function getAttachStdin() |
||
387 | |||
388 | /** |
||
389 | * @param bool $attachStdin |
||
390 | * |
||
391 | * @return self |
||
392 | */ |
||
393 | public function setAttachStdin($attachStdin = null) |
||
399 | |||
400 | /** |
||
401 | * @return bool |
||
402 | */ |
||
403 | public function getAttachStdout() |
||
407 | |||
408 | /** |
||
409 | * @param bool $attachStdout |
||
410 | * |
||
411 | * @return self |
||
412 | */ |
||
413 | public function setAttachStdout($attachStdout = null) |
||
419 | |||
420 | /** |
||
421 | * @return bool |
||
422 | */ |
||
423 | public function getAttachStderr() |
||
427 | |||
428 | /** |
||
429 | * @param bool $attachStderr |
||
430 | * |
||
431 | * @return self |
||
432 | */ |
||
433 | public function setAttachStderr($attachStderr = null) |
||
439 | |||
440 | /** |
||
441 | * @return bool |
||
442 | */ |
||
443 | public function getTty() |
||
447 | |||
448 | /** |
||
449 | * @param bool $tty |
||
450 | * |
||
451 | * @return self |
||
452 | */ |
||
453 | public function setTty($tty = null) |
||
459 | |||
460 | /** |
||
461 | * @return bool |
||
462 | */ |
||
463 | public function getOpenStdin() |
||
467 | |||
468 | /** |
||
469 | * @param bool $openStdin |
||
470 | * |
||
471 | * @return self |
||
472 | */ |
||
473 | public function setOpenStdin($openStdin = null) |
||
479 | |||
480 | /** |
||
481 | * @return bool |
||
482 | */ |
||
483 | public function getStdinOnce() |
||
487 | |||
488 | /** |
||
489 | * @param bool $stdinOnce |
||
490 | * |
||
491 | * @return self |
||
492 | */ |
||
493 | public function setStdinOnce($stdinOnce = null) |
||
499 | |||
500 | /** |
||
501 | * @return string[] |
||
502 | */ |
||
503 | public function getEnv() |
||
507 | |||
508 | /** |
||
509 | * @param string[] $env |
||
510 | * |
||
511 | * @return self |
||
512 | */ |
||
513 | public function setEnv(array $env = null) |
||
519 | |||
520 | /** |
||
521 | * @return string[]|string |
||
522 | */ |
||
523 | public function getCmd() |
||
527 | |||
528 | /** |
||
529 | * @param string[]|string $cmd |
||
530 | * |
||
531 | * @return self |
||
532 | */ |
||
533 | public function setCmd($cmd = null) |
||
539 | |||
540 | /** |
||
541 | * @return string[]|string |
||
542 | */ |
||
543 | public function getEntrypoint() |
||
547 | |||
548 | /** |
||
549 | * @param string[]|string $entrypoint |
||
550 | * |
||
551 | * @return self |
||
552 | */ |
||
553 | public function setEntrypoint($entrypoint = null) |
||
559 | |||
560 | /** |
||
561 | * @return Mount[] |
||
562 | */ |
||
563 | public function getMounts() |
||
567 | |||
568 | /** |
||
569 | * @param Mount[] $mounts |
||
570 | * |
||
571 | * @return self |
||
572 | */ |
||
573 | public function setMounts(array $mounts = null) |
||
579 | |||
580 | /** |
||
581 | * @return string |
||
582 | */ |
||
583 | public function getWorkingDir() |
||
587 | |||
588 | /** |
||
589 | * @param string $workingDir |
||
590 | * |
||
591 | * @return self |
||
592 | */ |
||
593 | public function setWorkingDir($workingDir = null) |
||
599 | |||
600 | /** |
||
601 | * @return bool |
||
602 | */ |
||
603 | public function getNetworkDisabled() |
||
607 | |||
608 | /** |
||
609 | * @param bool $networkDisabled |
||
610 | * |
||
611 | * @return self |
||
612 | */ |
||
613 | public function setNetworkDisabled($networkDisabled = null) |
||
619 | |||
620 | /** |
||
621 | * @return string |
||
622 | */ |
||
623 | public function getMacAddress() |
||
627 | |||
628 | /** |
||
629 | * @param string $macAddress |
||
630 | * |
||
631 | * @return self |
||
632 | */ |
||
633 | public function setMacAddress($macAddress = null) |
||
639 | |||
640 | /** |
||
641 | * @return mixed[] |
||
642 | */ |
||
643 | public function getExposedPorts() |
||
647 | |||
648 | /** |
||
649 | * @param mixed[] $exposedPorts |
||
650 | * |
||
651 | * @return self |
||
652 | */ |
||
653 | public function setExposedPorts(\ArrayObject $exposedPorts = null) |
||
659 | |||
660 | /** |
||
661 | * @return HostConfig |
||
662 | */ |
||
663 | public function getHostConfig() |
||
667 | |||
668 | /** |
||
669 | * @param HostConfig $hostConfig |
||
670 | * |
||
671 | * @return self |
||
672 | */ |
||
673 | public function setHostConfig(HostConfig $hostConfig = null) |
||
679 | } |
||
680 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needle
but will only accept an array as$haystack
.