Complex classes like ManifestManager 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 ManifestManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class ManifestManager |
||
|
|||
31 | { |
||
32 | /** |
||
33 | * @var array contains the module informations |
||
34 | */ |
||
35 | private static $modulesInfo = false; |
||
36 | |||
37 | /** |
||
38 | * @var array contains the system-wide module registry |
||
39 | */ |
||
40 | private static $modulesRegistry = false; |
||
41 | |||
42 | /** |
||
43 | * Setter for module infos. |
||
44 | * |
||
45 | * @param array $module_infos_array |
||
46 | */ |
||
47 | public static function setModuleInformations($module_infos_array) |
||
51 | |||
52 | /** |
||
53 | * Setter for modules registry. |
||
54 | * |
||
55 | * @param array $module_registry_array |
||
56 | */ |
||
57 | public static function setModuleRegistry($module_registry_array) |
||
61 | |||
62 | /** |
||
63 | * Reads the CMS Module Registry. |
||
64 | * |
||
65 | * This is the right method if you want to know if |
||
66 | * a module is installed and active or deactivated. |
||
67 | * |
||
68 | * @return array Module Registry Array |
||
69 | */ |
||
70 | public static function readModuleRegistry() |
||
71 | { |
||
72 | return \Koch\Config\Config()->read(APPLICATION_PATH . 'configuration/modules.config.php'); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Writes the Module Registry. |
||
77 | * |
||
78 | * @param array $array The Module Registry Array to write. |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | public static function writeModuleRegistry($array) |
||
83 | { |
||
84 | return \Koch\Config\Config()->write(APPLICATION_PATH . 'configuration/modules.config.php'); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Returns the module configuration as array. |
||
89 | * |
||
90 | * @param string $modulename |
||
91 | * |
||
92 | * @return array Module Configuration Array |
||
93 | */ |
||
94 | public static function readModuleConfig($modulename) |
||
98 | |||
99 | /** |
||
100 | * Checks if a modulename belongs to the core modules. |
||
101 | * |
||
102 | * @param string $modulename The modulename |
||
103 | * |
||
104 | * @return bool True if modulename is a core module, false otherwise. |
||
105 | */ |
||
106 | public static function isCoreModule($modulename) |
||
107 | { |
||
108 | // hardcoded map with core modules |
||
109 | static $core_modules = ['account', 'categories', 'controlcenter', 'doctrine', 'menu', 'modulemanager', |
||
110 | 'users', 'settings', 'systeminfo', 'thememanager', 'templatemanager', ]; |
||
111 | |||
112 | // @todo extract from module info file if core module or not |
||
113 | return in_array($modulename, $core_modules, true); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Get a list of all the module directories. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | public static function getModuleDirectories() |
||
122 | { |
||
123 | return glob(APPLICATION_MODULES_PATH . '[a-zA-Z]*', GLOB_ONLYDIR); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Get a list of all the module names. |
||
128 | * |
||
129 | * 4 in 1 method, handling the following cases: |
||
130 | * 1. array with module names |
||
131 | * 2. named array with modulenames |
||
132 | * 3. array with module names and paths |
||
133 | * 4. named array with modulenames and paths |
||
134 | * |
||
135 | * @param bool $only_modulenames Toggle between only_names (true) and names+paths. |
||
136 | * @param bool $named_array Toggle between named (true) and unnamed array. |
||
137 | * |
||
138 | * @return array( $modulename => $module_path ) |
||
139 | */ |
||
140 | public static function getModuleNames($named_array = false, $only_modulenames = false) |
||
141 | { |
||
142 | $modules = []; |
||
143 | |||
144 | $module_dirs = self::getModuleDirectories(); |
||
145 | |||
146 | foreach ($module_dirs as $module_path) { |
||
147 | // strip path off |
||
148 | $modulename = str_replace(APPLICATION_MODULES_PATH, '', $module_path); |
||
149 | |||
150 | if ($only_modulenames === true) { |
||
151 | if ($named_array === false) { |
||
152 | $modules[] = $modulename; |
||
153 | } else { |
||
154 | $modules[] = ['name' => $modulename]; |
||
155 | } |
||
156 | } else { |
||
157 | if ($named_array === false) { |
||
158 | $modules[] = [$modulename => $module_path]; |
||
159 | } else { |
||
160 | $modules[] = ['name' => $modulename, 'path' => $module_path]; |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | |||
165 | return $modules; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Returns all activated modules. |
||
170 | * |
||
171 | * @return array $activated_modules_array |
||
172 | */ |
||
173 | public static function getAllActivatedModules() |
||
174 | { |
||
175 | $activated_modules_array = []; |
||
176 | |||
177 | $modules = self::getModuleNames(true); |
||
178 | |||
179 | foreach ($modules as $module) { |
||
180 | if (true === self::isModuleActive($module)) { |
||
181 | $activated_modules_array[$module] = self::$modulesRegistry[$module]; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | return $activated_modules_array; |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Checks if a module is active or deactived. |
||
190 | * |
||
191 | * @param bool $module True if module activated, false otherwise. |
||
192 | */ |
||
193 | public static function isModuleActive($module) |
||
194 | { |
||
195 | // load module registry, if not available yet |
||
196 | if (empty(self::$modulesRegistry[$module])) { |
||
197 | self::$modulesRegistry = self::readModuleRegistry(); |
||
198 | } |
||
199 | |||
200 | // check, if the module is |
||
201 | if (isset(self::$modulesRegistry[$module]['active']) and self::$modulesRegistry[$module]['active'] === true) { |
||
202 | return true; |
||
203 | } else { |
||
204 | return false; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Fetches all pieces of information of a certain module. |
||
210 | * |
||
211 | * @param string $module |
||
212 | * |
||
213 | * @return array Module Informations |
||
214 | */ |
||
215 | public static function getModuleInformations($module = null) |
||
227 | |||
228 | public static function buildModuleRegistry() |
||
229 | { |
||
230 | foreach ($module_directories as $module_path) { |
||
231 | // strip off path info and get the modulename |
||
232 | $modulename = str_replace(APPLICATION_MODULES_PATH, '', $module_path); |
||
233 | } |
||
234 | |||
237 | |||
238 | /** |
||
239 | * Gather Module Informations from Manifest Files. |
||
240 | * |
||
241 | * @staticvar array $modulesinfo |
||
242 | * |
||
243 | * @param mixed array|string $module array with modulenames or one modulename |
||
244 | * @param string $module |
||
245 | * |
||
246 | * @return moduleinformations (self::$modulesinfo) |
||
247 | */ |
||
248 | public static function loadModuleInformations($module = null) |
||
326 | |||
327 | public static function getLanguageInfosForModule($modulepath) |
||
409 | |||
410 | /** |
||
411 | * Returns file permissions as string. |
||
412 | * |
||
413 | * @staticvar array $permissions |
||
414 | * |
||
415 | * @param type $filename |
||
416 | * |
||
417 | * @return string File Permissions as string, e.h. "rwx", "rw-" |
||
418 | */ |
||
419 | private static function filePermissions($filename) |
||
431 | } |
||
432 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.