Complex classes like PHPConsoleHandler 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 PHPConsoleHandler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class PHPConsoleHandler extends AbstractProcessingHandler |
||
41 | { |
||
42 | private $options = array( |
||
43 | 'enabled' => true, // bool Is PHP Console server enabled |
||
44 | 'classesPartialsTraceIgnore' => array('Monolog\\'), // array Hide calls of classes started with... |
||
45 | 'debugTagsKeysInContext' => array(0, 'tag'), // bool Is PHP Console server enabled |
||
46 | 'useOwnErrorsHandler' => false, // bool Enable errors handling |
||
47 | 'useOwnExceptionsHandler' => false, // bool Enable exceptions handling |
||
48 | 'sourcesBasePath' => null, // string Base path of all project sources to strip in errors source paths |
||
49 | 'registerHelper' => true, // bool Register PhpConsole\Helper that allows short debug calls like PC::debug($var, 'ta.g.s') |
||
50 | 'serverEncoding' => null, // string|null Server internal encoding |
||
51 | 'headersLimit' => null, // int|null Set headers size limit for your web-server |
||
52 | 'password' => null, // string|null Protect PHP Console connection by password |
||
53 | 'enableSslOnlyMode' => false, // bool Force connection by SSL for clients with PHP Console installed |
||
54 | 'ipMasks' => array(), // array Set IP masks of clients that will be allowed to connect to PHP Console: array('192.168.*.*', '127.0.0.1') |
||
55 | 'enableEvalListener' => false, // bool Enable eval request to be handled by eval dispatcher(if enabled, 'password' option is also required) |
||
56 | 'dumperDetectCallbacks' => false, // bool Convert callback items in dumper vars to (callback SomeClass::someMethod) strings |
||
57 | 'dumperLevelLimit' => 5, // int Maximum dumped vars array or object nested dump level |
||
58 | 'dumperItemsCountLimit' => 100, // int Maximum dumped var same level array items or object properties number |
||
59 | 'dumperItemSizeLimit' => 5000, // int Maximum length of any string or dumped array item |
||
60 | 'dumperDumpSizeLimit' => 500000, // int Maximum approximate size of dumped vars result formatted in JSON |
||
61 | 'detectDumpTraceAndSource' => false, // bool Autodetect and append trace data to debug |
||
62 | 'dataStorage' => null, // PhpConsole\Storage|null Fixes problem with custom $_SESSION handler(see http://goo.gl/Ne8juJ) |
||
63 | ); |
||
64 | |||
65 | /** @var Connector */ |
||
66 | private $connector; |
||
67 | |||
68 | /** |
||
69 | * @param array $options See \Monolog\Handler\PHPConsoleHandler::$options for more details |
||
70 | * @param Connector|null $connector Instance of \PhpConsole\Connector class (optional) |
||
71 | * @param int $level |
||
72 | * @param bool $bubble |
||
73 | * @throws Exception |
||
74 | */ |
||
75 | public function __construct(array $options = array(), Connector $connector = null, $level = Logger::DEBUG, $bubble = true) |
||
84 | |||
85 | private function initOptions(array $options) |
||
94 | |||
95 | private function initConnector(Connector $connector = null) |
||
149 | |||
150 | public function getConnector() |
||
154 | |||
155 | public function getOptions() |
||
159 | |||
160 | public function handle(array $record) |
||
168 | |||
169 | /** |
||
170 | * Writes the record down to the log of the implementing handler |
||
171 | * |
||
172 | * @param array $record |
||
173 | * @return void |
||
174 | */ |
||
175 | protected function write(array $record) |
||
185 | |||
186 | private function handleDebugRecord(array $record) |
||
195 | |||
196 | private function handleExceptionRecord(array $record) |
||
200 | |||
201 | private function handleErrorRecord(array $record) |
||
213 | |||
214 | private function getRecordTags(array &$record) |
||
234 | |||
235 | /** |
||
236 | * {@inheritDoc} |
||
237 | */ |
||
238 | protected function getDefaultFormatter() |
||
242 | } |
||
243 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.