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