Complex classes like _Object 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 _Object, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class _Object implements \ArrayAccess |
||
20 | { |
||
21 | use \PHPDaemon\Traits\ClassWatchdog; |
||
22 | |||
23 | /** |
||
24 | * Maximum memory usage |
||
25 | * @var size |
||
26 | */ |
||
27 | public $maxmemoryusage = '0b'; |
||
28 | |||
29 | /** |
||
30 | * Maximum idle time |
||
31 | * @var time |
||
32 | */ |
||
33 | public $maxidle = '0s'; |
||
34 | |||
35 | /** |
||
36 | * PID file |
||
37 | * @var string|Entry\Generic |
||
38 | */ |
||
39 | public $pidfile = '/var/run/phpd.pid'; |
||
40 | |||
41 | /** |
||
42 | * Default namespace |
||
43 | * @var path |
||
44 | */ |
||
45 | public $defaultns = 'PHPDaemon'; |
||
46 | |||
47 | /** |
||
48 | * Default PID file |
||
49 | * @var path |
||
50 | */ |
||
51 | public $defaultpidfile = '/var/run/phpd.pid'; |
||
52 | |||
53 | /** |
||
54 | * Config file |
||
55 | * @var string|Entry\ConfigFile |
||
56 | */ |
||
57 | public $configfile = '/etc/phpdaemon/phpd.conf;/etc/phpd/phpd.conf;./conf/phpd.conf'; |
||
58 | |||
59 | /** |
||
60 | * Application resolver |
||
61 | * @var string|Entry\Generic |
||
62 | */ |
||
63 | public $path = '/etc/phpdaemon/AppResolver.php;./conf/AppResolver.php'; |
||
64 | |||
65 | /** |
||
66 | * Additional include path |
||
67 | * @var string|Entry\Generic |
||
68 | */ |
||
69 | public $addincludepath = null; |
||
70 | |||
71 | /** |
||
72 | * Multi-Process Manager delay |
||
73 | * @var time |
||
74 | */ |
||
75 | public $mpmdelay = '0.1s'; |
||
76 | |||
77 | /** |
||
78 | * Max. requests before worker restart |
||
79 | * @var int|Entry\Number |
||
80 | */ |
||
81 | public $maxrequests = '10k'; |
||
82 | |||
83 | /** |
||
84 | * Start workers |
||
85 | * @var int|Entry\Number |
||
86 | */ |
||
87 | public $startworkers = 4; |
||
88 | |||
89 | /** |
||
90 | * Minimum number of workers |
||
91 | * @var int|Entry\Number |
||
92 | */ |
||
93 | public $minworkers = 4; |
||
94 | |||
95 | /** |
||
96 | * Maximum number of workers |
||
97 | * @var int|Entry\Number |
||
98 | */ |
||
99 | public $maxworkers = 8; |
||
100 | |||
101 | /** |
||
102 | * Minimum number of spare workes |
||
103 | * @var int|Entry\Number |
||
104 | */ |
||
105 | public $minspareworkers = 2; |
||
106 | |||
107 | /** |
||
108 | * Maximum number of spare workes |
||
109 | * @var int|Entry\Number |
||
110 | */ |
||
111 | public $maxspareworkers = 0; |
||
112 | |||
113 | /** |
||
114 | * Master thread priority |
||
115 | * @var integer |
||
116 | */ |
||
117 | public $masterpriority = 100; |
||
118 | |||
119 | /** |
||
120 | * IPC thread priority |
||
121 | * @var integer |
||
122 | */ |
||
123 | public $ipcthreadpriority = 100; |
||
124 | |||
125 | /** |
||
126 | * IPC thread priority |
||
127 | * @var boolean |
||
128 | */ |
||
129 | public $obfilterauto = 1; |
||
130 | |||
131 | /** |
||
132 | * System user (setuid) |
||
133 | * @var string|Entry\Generic |
||
134 | */ |
||
135 | public $user = null; |
||
136 | |||
137 | /** |
||
138 | * System group (setgid) |
||
139 | * @var string|Entry\Generic |
||
140 | */ |
||
141 | public $group = null; |
||
142 | |||
143 | /** |
||
144 | * Automatic garbage collector, number of iterations between GC call |
||
145 | * @var int|Entry\Number |
||
146 | */ |
||
147 | public $autogc = '1k'; |
||
148 | |||
149 | /** |
||
150 | * Chroot |
||
151 | * @var string|Entry\Generic |
||
152 | */ |
||
153 | public $chroot = '/'; |
||
154 | |||
155 | /** |
||
156 | * Current directory |
||
157 | * @var string |
||
158 | */ |
||
159 | public $cwd = '.'; |
||
160 | |||
161 | /** |
||
162 | * Autoreload interval. Time interval between checks. |
||
163 | * @var time |
||
164 | */ |
||
165 | public $autoreload = '0s'; |
||
166 | |||
167 | /** |
||
168 | * Try to import updated code (runkit required) |
||
169 | * @var boolean|Entry\Generic |
||
170 | */ |
||
171 | public $autoreimport = 0; |
||
172 | |||
173 | /** |
||
174 | * Worker thread priority |
||
175 | * @var integer |
||
176 | */ |
||
177 | public $workerpriority = 4; |
||
178 | |||
179 | /** |
||
180 | * Lambda cache size |
||
181 | * @var integer |
||
182 | */ |
||
183 | public $lambdacachemaxsize = 128; |
||
184 | |||
185 | /** |
||
186 | * Lambda cache cap window |
||
187 | * @var integer |
||
188 | */ |
||
189 | public $lambdacachecapwindow = 32; |
||
190 | |||
191 | /** |
||
192 | * Lambda cache ttl |
||
193 | * @var integer |
||
194 | */ |
||
195 | public $lambdacachettl = 0; |
||
196 | |||
197 | /** |
||
198 | * Throw exception on shutdown? |
||
199 | * @var boolean |
||
200 | */ |
||
201 | public $throwexceptiononshutdown = 0; |
||
202 | |||
203 | /** |
||
204 | * Comma-separated list of locales |
||
205 | * @var string|Entry\Generic |
||
206 | */ |
||
207 | public $locale = ''; |
||
208 | |||
209 | /** |
||
210 | * Restrict usage of error-control functions (like @ operator), useful in debugging |
||
211 | * @var boolean |
||
212 | */ |
||
213 | public $restricterrorcontrol = false; |
||
214 | |||
215 | // Logging-related |
||
216 | |||
217 | /** |
||
218 | * Logging? |
||
219 | * @var boolean |
||
220 | */ |
||
221 | public $logging = 1; |
||
222 | |||
223 | /** |
||
224 | * Log storage |
||
225 | * @var boolean|Entry\Generic |
||
226 | */ |
||
227 | public $logstorage = '/var/log/phpdaemon.log'; |
||
228 | |||
229 | /** |
||
230 | * Log format |
||
231 | * @var string |
||
232 | */ |
||
233 | public $logformat = '[D, j M Y H:i:s.u O] %msg%'; |
||
234 | |||
235 | /** |
||
236 | * Log errors? |
||
237 | * @var boolean |
||
238 | */ |
||
239 | public $logerrors = 1; |
||
240 | |||
241 | /** |
||
242 | * Log Worker->setState() ? |
||
243 | * @var boolean |
||
244 | */ |
||
245 | public $logworkersetstate = 0; |
||
246 | |||
247 | /** |
||
248 | * Log signals? |
||
249 | * @var boolean |
||
250 | */ |
||
251 | public $logsignals = 0; |
||
252 | |||
253 | /** |
||
254 | * Do not close STDOUT and STDERR pipes and send log messages there |
||
255 | * @var boolean |
||
256 | */ |
||
257 | public $verbosetty = 0; |
||
258 | |||
259 | /** |
||
260 | * EIO enabled? |
||
261 | * @var boolean |
||
262 | */ |
||
263 | public $eioenabled = 1; |
||
264 | |||
265 | /** |
||
266 | * EIO maximum idle time |
||
267 | * @var time |
||
268 | */ |
||
269 | public $eiosetmaxidle = null; |
||
270 | |||
271 | /** |
||
272 | * EIO maximum parallel threads |
||
273 | * @var int|Entry\Number |
||
274 | */ |
||
275 | public $eiosetmaxparallel = null; |
||
276 | |||
277 | /** |
||
278 | * EIO maximum poll requests |
||
279 | * @var int|Entry\Number |
||
280 | */ |
||
281 | public $eiosetmaxpollreqs = null; |
||
282 | |||
283 | /** |
||
284 | * EIO maximum poll time |
||
285 | * @var time |
||
286 | */ |
||
287 | public $eiosetmaxpolltime = null; |
||
288 | |||
289 | /** |
||
290 | * EIO minimum parallel threads |
||
291 | * @var int|Entry\Number |
||
292 | */ |
||
293 | public $eiosetminparallel = null; |
||
294 | |||
295 | /** @var int */ |
||
296 | public static $lastRevision = 0; |
||
297 | |||
298 | /** |
||
299 | * Constructor |
||
300 | * @return _Object |
||
301 | */ |
||
|
|||
302 | |||
303 | public function __construct() |
||
350 | |||
351 | /** |
||
352 | * Renames section |
||
353 | * @param string $old |
||
354 | * @param string $new |
||
355 | * @param boolean $log Log? |
||
356 | * @return void |
||
357 | */ |
||
358 | public function renameSection($old, $new, $log = false) |
||
366 | |||
367 | /** |
||
368 | * Load config file |
||
369 | * @param string Path |
||
370 | * @return boolean Success |
||
371 | */ |
||
372 | public function loadFile($path) |
||
378 | |||
379 | /** |
||
380 | * Called when config is loaded |
||
381 | * @return void |
||
382 | */ |
||
383 | protected function onLoad() |
||
400 | |||
401 | /** |
||
402 | * Get real property name |
||
403 | * @param string Property name |
||
404 | * @return string Real property name |
||
405 | */ |
||
406 | public function getRealPropertyName($prop) |
||
410 | |||
411 | /** |
||
412 | * Checks if property exists |
||
413 | * @param string Property name |
||
414 | * @return boolean Exists? |
||
415 | */ |
||
416 | |||
417 | public function offsetExists($prop) |
||
422 | |||
423 | /** |
||
424 | * Get property by name |
||
425 | * @param string Property name |
||
426 | * @return mixed |
||
427 | */ |
||
428 | public function offsetGet($prop) |
||
433 | |||
434 | /** |
||
435 | * Set property |
||
436 | * @param string Property name |
||
437 | * @param mixed Value |
||
438 | * @return void |
||
439 | */ |
||
440 | public function offsetSet($prop, $value) |
||
445 | |||
446 | /** |
||
447 | * Unset property |
||
448 | * @param string Property name |
||
449 | * @return void |
||
450 | */ |
||
451 | public function offsetUnset($prop) |
||
456 | |||
457 | /** |
||
458 | * Checks if property exists |
||
459 | * @param string Property name |
||
460 | * @return boolean Exists? |
||
461 | */ |
||
462 | public static function parseCfgUri($uri, $source = null) |
||
524 | |||
525 | /** |
||
526 | * Imports parameters from command line args |
||
527 | * @param array Settings. |
||
528 | * @return boolean - Success. |
||
529 | */ |
||
530 | public static function loadCmdLineArgs($settings) |
||
561 | } |
||
562 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.