Complex classes like CacheManager 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 CacheManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
44 | class CacheManager |
||
45 | { |
||
46 | /** |
||
47 | * @var int |
||
48 | */ |
||
49 | public static $ReadHits = 0; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | public static $WriteHits = 0; |
||
55 | |||
56 | /** |
||
57 | * @var ExtendedCacheItemPoolInterface[] |
||
58 | */ |
||
59 | protected static $config = [ |
||
60 | /** |
||
61 | * Specify if the item must provide detailed creation/modification dates |
||
62 | */ |
||
63 | 'itemDetailedDate' => false, |
||
64 | |||
65 | /** |
||
66 | * Automatically attempt to fallback to temporary directory |
||
67 | * if the cache fails to write on the specified directory |
||
68 | */ |
||
69 | 'autoTmpFallback' => false, |
||
70 | |||
71 | /** |
||
72 | * Provide a secure file manipulation mechanism |
||
73 | * on intensive usage the performance can be affected. |
||
74 | */ |
||
75 | 'secureFileManipulation' => false, |
||
76 | |||
77 | /** |
||
78 | * Ignore Symfony notice for Symfony project which |
||
79 | * do not makes use of PhpFastCache's Symfony Bundle |
||
80 | */ |
||
81 | 'ignoreSymfonyNotice' => false, |
||
82 | |||
83 | /** |
||
84 | * Default time-to-live in second |
||
85 | */ |
||
86 | 'defaultTtl' => 900, |
||
87 | |||
88 | /** |
||
89 | * Default key hash function |
||
90 | * (md5 by default) |
||
91 | */ |
||
92 | 'defaultKeyHashFunction' => '', |
||
93 | |||
94 | /** |
||
95 | * The securityKey that will be used |
||
96 | * to create sub-directory |
||
97 | * (Files-based drivers only) |
||
98 | */ |
||
99 | 'securityKey' => 'auto', |
||
100 | |||
101 | /** |
||
102 | * Auto-generate .htaccess if it's missing |
||
103 | * (Files-based drivers only) |
||
104 | */ |
||
105 | 'htaccess' => true, |
||
106 | |||
107 | /** |
||
108 | * Default files chmod |
||
109 | * 0777 recommended |
||
110 | * (Files-based drivers only) |
||
111 | */ |
||
112 | 'default_chmod' => 0777, |
||
113 | |||
114 | /** |
||
115 | * The path where we will writecache files |
||
116 | * default value if empty: sys_get_temp_dir() |
||
117 | * (Files-based drivers only) |
||
118 | */ |
||
119 | 'path' => '', |
||
120 | |||
121 | /** |
||
122 | * Driver fallback in case of failure. |
||
123 | * Caution, in case of failure an E_WARNING |
||
124 | * error will always be raised |
||
125 | */ |
||
126 | 'fallback' => false, |
||
127 | |||
128 | /** |
||
129 | * Maximum size (bytes) of object store in memory |
||
130 | * (Memcache(d) drivers only) |
||
131 | */ |
||
132 | 'limited_memory_each_object' => 4096, |
||
133 | |||
134 | /** |
||
135 | * Compress stored data, if the backend supports it |
||
136 | * (Memcache(d) drivers only) |
||
137 | */ |
||
138 | 'compress_data' => false, |
||
139 | ]; |
||
140 | |||
141 | /** |
||
142 | * @var string |
||
143 | */ |
||
144 | protected static $namespacePath; |
||
145 | |||
146 | /** |
||
147 | * @var ExtendedCacheItemPoolInterface[] |
||
148 | */ |
||
149 | protected static $instances = []; |
||
150 | |||
151 | /** |
||
152 | * @param string $driver |
||
153 | * @param array $config |
||
154 | * @return ExtendedCacheItemPoolInterface |
||
155 | * @throws phpFastCacheDriverCheckException |
||
156 | */ |
||
157 | public static function getInstance($driver = 'auto', array $config = []) |
||
199 | |||
200 | /** |
||
201 | * This method is intended for internal |
||
202 | * use only and should not be used for |
||
203 | * any external development use the |
||
204 | * getInstances() method instead |
||
205 | * |
||
206 | * @internal |
||
207 | * @return ExtendedCacheItemPoolInterface[] |
||
208 | */ |
||
209 | public static function getInstances() |
||
213 | |||
214 | /** |
||
215 | * This method is intended for internal |
||
216 | * use only and should not be used for |
||
217 | * any external development use the |
||
218 | * getInstances() method instead |
||
219 | * |
||
220 | * @internal |
||
221 | * @return ExtendedCacheItemPoolInterface[] |
||
222 | */ |
||
223 | public static function &getInternalInstances() |
||
227 | |||
228 | /** |
||
229 | * @param $config |
||
230 | * @return string |
||
231 | * @throws phpFastCacheDriverCheckException |
||
232 | */ |
||
233 | public static function getAutoClass(array $config = []) |
||
250 | |||
251 | /** |
||
252 | * @param string $name |
||
253 | * @param array $arguments |
||
254 | * @return \Psr\Cache\CacheItemPoolInterface |
||
255 | */ |
||
256 | public static function __callStatic($name, $arguments) |
||
262 | |||
263 | /** |
||
264 | * @return bool |
||
265 | */ |
||
266 | public static function clearInstances() |
||
273 | |||
274 | /** |
||
275 | * @return string |
||
276 | */ |
||
277 | public static function getNamespacePath() |
||
281 | |||
282 | /** |
||
283 | * @param string $path |
||
284 | */ |
||
285 | public static function setNamespacePath($path) |
||
289 | |||
290 | /** |
||
291 | * @param $name string|array |
||
292 | * @param mixed $value |
||
293 | * @throws phpFastCacheInvalidArgumentException |
||
294 | */ |
||
295 | public static function setDefaultConfig($name, $value = null) |
||
305 | |||
306 | /** |
||
307 | * @return array |
||
308 | */ |
||
309 | public static function getDefaultConfig() |
||
313 | |||
314 | /** |
||
315 | * @return array |
||
316 | */ |
||
317 | public static function getStaticSystemDrivers() |
||
339 | |||
340 | /** |
||
341 | * @return array |
||
342 | */ |
||
343 | public static function getStaticAllDrivers() |
||
351 | |||
352 | /** |
||
353 | * @param string $driverName |
||
354 | * @return string |
||
355 | */ |
||
356 | public static function standardizeDriverName($driverName) |
||
360 | |||
361 | /** |
||
362 | * @param array $config |
||
363 | * @todo Move this to a config file |
||
364 | * @throws phpFastCacheInvalidConfigurationException |
||
365 | * @return bool |
||
366 | */ |
||
367 | protected static function validateConfig(array $config) |
||
442 | } |
||
443 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..