Complex classes like ConfigCache 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 ConfigCache, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
42 | class ConfigCache |
||
43 | { |
||
44 | const CACHE_SUBDIR = 'config'; |
||
45 | |||
46 | /** |
||
47 | * @var array An array of config handler instructions. |
||
48 | */ |
||
49 | protected static $handlers = null; |
||
50 | |||
51 | /** |
||
52 | * @var array A string=>bool array containing config handler files and |
||
53 | * their loaded status. |
||
54 | */ |
||
55 | protected static $handlerFiles = array(); |
||
56 | |||
57 | /** |
||
58 | * @var bool Whether there is an entry in self::$handlerFiles that |
||
59 | * needs processing. |
||
60 | */ |
||
61 | protected static $handlersDirty = true; |
||
62 | |||
63 | /** |
||
64 | * @var bool Whether the config handler files have been required. |
||
65 | */ |
||
66 | protected static $filesIncluded = false; |
||
67 | |||
68 | /** |
||
69 | * Load a configuration handler. |
||
70 | * |
||
71 | * @param string $name The path of the originally requested configuration file. |
||
72 | * @param string $config An absolute filesystem path to a configuration file. |
||
73 | * @param string $cache An absolute filesystem path to the cache file that |
||
74 | * will be written. |
||
75 | * @param string $context The context which we're currently running. |
||
76 | * @param array $handlerInfo Optional config handler info array. |
||
77 | * |
||
78 | * @throws <b>ConfigurationException</b> If a requested configuration |
||
79 | * file does not have an |
||
80 | * associated config handler. |
||
81 | * |
||
82 | * @author David Zülke <[email protected]> |
||
83 | * @author Dominik del Bondio <[email protected]> |
||
84 | * @author Felix Gilcher <[email protected]> |
||
85 | * @since 0.9.0 |
||
86 | */ |
||
87 | protected static function callHandler($name, $config, $cache, $context, array $handlerInfo = null) |
||
106 | |||
107 | /** |
||
108 | * Set up all config handler definitions. |
||
109 | * |
||
110 | * Checks whether the handlers have been loaded or the dirtyHandlers flat is |
||
111 | * set, and loads any handler that has not been loaded. |
||
112 | * |
||
113 | * @author Felix Gilcher <[email protected]> |
||
114 | * @since 1.0.0 |
||
115 | */ |
||
116 | protected static function setupHandlers() |
||
132 | |||
133 | /** |
||
134 | * Fetch the handler information for the given filename. |
||
135 | * |
||
136 | * @param string $name The name of the config file (partial path). |
||
137 | * |
||
138 | * @return array The handler info. |
||
139 | * |
||
140 | * @author Felix Gilcher <[email protected]> |
||
141 | * @since 1.0.0 |
||
142 | */ |
||
143 | protected static function getHandlerInfo($name) |
||
172 | |||
173 | /** |
||
174 | * Execute the config handler for the given file. |
||
175 | * |
||
176 | * @param string $config The path to the config file (full path). |
||
177 | * @param string $context The context which we're currently running. |
||
178 | * @param array $handlerInfo The config handler info. |
||
179 | * |
||
180 | * @return string The compiled data. |
||
181 | * |
||
182 | * @author Felix Gilcher <[email protected]> |
||
183 | * @since 1.0.0 |
||
184 | */ |
||
185 | protected static function executeHandler($config, $context, array $handlerInfo) |
||
217 | |||
218 | /** |
||
219 | * Check to see if a configuration file has been modified and if so |
||
220 | * recompile the cache file associated with it. |
||
221 | * |
||
222 | * If the configuration file path is relative, the path itself is relative |
||
223 | * to the Agavi "core.app_dir" application setting. |
||
224 | * |
||
225 | * @param string $config A filesystem path to a configuration file. |
||
226 | * @param string $context An optional context name for which the config should be read. |
||
227 | * |
||
228 | * @return string An absolute filesystem path to the cache filename |
||
229 | * associated with this specified configuration file. |
||
230 | * |
||
231 | * @throws <b>UnreadableException</b> If a requested configuration |
||
232 | * file does not exist. |
||
233 | * |
||
234 | * @author Sean Kerr <[email protected]> |
||
235 | * @since 0.9.0 |
||
236 | */ |
||
237 | public static function checkConfig($config, $context = null) |
||
258 | |||
259 | /** |
||
260 | * Check if the cached version of a file is up to date. |
||
261 | * |
||
262 | * @param string $filename The source file. |
||
263 | * @param string $cachename The name of the cached version. |
||
264 | * |
||
265 | * @return bool Whether or not the cached file must be updated. |
||
266 | * |
||
267 | * @author David Zülke <[email protected]> |
||
268 | * @since 0.11.0 |
||
269 | */ |
||
270 | public static function isModified($filename, $cachename) |
||
274 | |||
275 | /** |
||
276 | * Clear all configuration cache files. |
||
277 | * |
||
278 | * @author Sean Kerr <[email protected]> |
||
279 | * @since 0.9.0 |
||
280 | */ |
||
281 | public static function clear() |
||
285 | |||
286 | /** |
||
287 | * Convert a normal filename into a cache filename. |
||
288 | * |
||
289 | * @param string $config A normal filename. |
||
290 | * @param string $context A context name. |
||
291 | * |
||
292 | * @return string An absolute filesystem path to a cache filename. |
||
293 | * |
||
294 | * @author Sean Kerr <[email protected]> |
||
295 | * @since 0.9.0 |
||
296 | */ |
||
297 | public static function getCacheName($config, $context = null) |
||
332 | |||
333 | /** |
||
334 | * Import a configuration file. |
||
335 | * |
||
336 | * If the configuration file path is relative, the path itself is relative |
||
337 | * to the Agavi "core.app_dir" application setting. |
||
338 | * |
||
339 | * @param string $config A filesystem path to a configuration file. |
||
340 | * @param string $context A context name. |
||
341 | * @param bool $once Only allow this configuration file to be included once |
||
342 | * per request? |
||
343 | * |
||
344 | * @author Sean Kerr <[email protected]> |
||
345 | * @since 0.9.0 |
||
346 | */ |
||
347 | public static function load($config, $context = null, $once = true) |
||
357 | |||
358 | /** |
||
359 | * Load all configuration application and module level handlers. |
||
360 | * |
||
361 | * @throws ConfigurationException If a configuration related |
||
362 | * error occurs. |
||
363 | * |
||
364 | * @author Sean Kerr <[email protected]> |
||
365 | * @since 0.9.0 |
||
366 | */ |
||
367 | protected static function loadConfigHandlers() |
||
467 | |||
468 | /** |
||
469 | * Load the config handlers from the given config file. |
||
470 | * Existing handlers will not be overwritten. |
||
471 | * |
||
472 | * @param string $cfg The path to a config_handlers.xml file. |
||
473 | * |
||
474 | * @author Felix Gilcher <[email protected]> |
||
475 | * @since 1.0.0 |
||
476 | */ |
||
477 | protected static function loadConfigHandlersFile($cfg) |
||
481 | |||
482 | /** |
||
483 | * Schedules a config handlers file to be loaded. |
||
484 | * |
||
485 | * @param string $filename The path to a config_handlers.xml file. |
||
486 | * |
||
487 | * @author Dominik del Bondio <[email protected]> |
||
488 | * @since 1.0.0 |
||
489 | */ |
||
490 | public static function addConfigHandlersFile($filename) |
||
501 | |||
502 | /** |
||
503 | * Write a cache file. |
||
504 | * |
||
505 | * @param string $config An absolute filesystem path to a configuration file. |
||
506 | * @param string $cache An absolute filesystem path to the cache file that |
||
507 | * will be written. |
||
508 | * @param string $data Data to be written to the cache file. |
||
509 | * @param bool $append Should we append the data? |
||
510 | * |
||
511 | * @throws <b>CacheException</b> If the cache file cannot be written. |
||
512 | * |
||
513 | * @author Sean Kerr <[email protected]> |
||
514 | * @since 0.9.0 |
||
515 | */ |
||
516 | public static function writeCacheFile($config, $cache, $data, $append = false) |
||
550 | |||
551 | /** |
||
552 | * Parses a config file with the ConfigParser for the extension of the given |
||
553 | * file. |
||
554 | * |
||
555 | * @param string $config An absolute filesystem path to a configuration file. |
||
556 | * @param bool $autoloadParser Whether the config parser class should be autoloaded if |
||
557 | * the class doesn't exist. |
||
558 | * @param string $validationFile A path to a validation file for this config file. |
||
559 | * @param string $parserClass A class name which specifies an parser to be used. |
||
560 | * |
||
561 | * @return ConfigValueHolder An abstract representation of the |
||
562 | * config file. |
||
563 | * |
||
564 | * @throws <b>AgaviConfigurationException</b> If the parser for the |
||
565 | * extension couldn't be found. |
||
566 | * |
||
567 | * @author Dominik del Bondio <[email protected]> |
||
568 | * @author David Zülke <[email protected]> |
||
569 | * @since 0.11.0 |
||
570 | * |
||
571 | * @deprecated New-style config handlers don't call this method anymore. To be |
||
572 | * removed in Agavi 1.1 |
||
573 | */ |
||
574 | public static function parseConfig($config, $autoloadParser = true, $validationFile = null, $parserClass = null) |
||
580 | } |
||
581 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: