Complex classes like PMF_System 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 PMF_System, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class PMF_System |
||
31 | { |
||
32 | /** |
||
33 | * Major version. |
||
34 | */ |
||
35 | const VERSION_MAJOR = 2; |
||
36 | |||
37 | /** |
||
38 | * Minor version. |
||
39 | */ |
||
40 | const VERSION_MINOR = 9; |
||
41 | |||
42 | /** |
||
43 | * Patchlevel. |
||
44 | */ |
||
45 | const VERSION_PATCHLEVEL = 0; |
||
46 | |||
47 | /** |
||
48 | * Pre-release version. |
||
49 | */ |
||
50 | const VERSION_PRERELEASE = 'RC2'; |
||
51 | |||
52 | /** |
||
53 | * API version. |
||
54 | */ |
||
55 | const VERSION_API = '1.1'; |
||
56 | |||
57 | /** |
||
58 | * Minimum required PHP version. |
||
59 | */ |
||
60 | const VERSION_MINIMUM_PHP = '5.5.0'; |
||
61 | |||
62 | /** |
||
63 | * Array of required PHP extensions. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | private $requiredExtensions = [ |
||
68 | 'curl', |
||
69 | 'gd', |
||
70 | 'json', |
||
71 | 'xmlwriter', |
||
72 | 'filter', |
||
73 | 'zip', |
||
74 | 'fileinfo' |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Array of missing PHP extensions. |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | private $missingExtensions = []; |
||
83 | |||
84 | /** |
||
85 | * Supported databases for phpMyFAQ. |
||
86 | * |
||
87 | * @var array |
||
88 | */ |
||
89 | private $supportedDatabases = [ |
||
90 | 'mysqli' => [ self::VERSION_MINIMUM_PHP, 'MySQL 5.x / Percona Server 5.x / MariaDB 5.x and later' ], |
||
91 | 'pgsql' => [ self::VERSION_MINIMUM_PHP, 'PostgreSQL 9.x' ], |
||
92 | 'sqlite3' => [ self::VERSION_MINIMUM_PHP, 'SQLite 3' ], |
||
93 | 'mssql' => [ self::VERSION_MINIMUM_PHP, 'MS SQL Server 2012 and later (deprecated)' ], |
||
94 | 'sqlsrv' => [ self::VERSION_MINIMUM_PHP, 'MS SQL Server 2012 Driver for PHP'] |
||
95 | ]; |
||
96 | |||
97 | /** |
||
98 | * Database handle. |
||
99 | * |
||
100 | * @var PMF_DB_Driver |
||
101 | */ |
||
102 | private $database = null; |
||
103 | |||
104 | /** |
||
105 | * Sets the database handler. |
||
106 | * |
||
107 | * @param PMF_DB_Driver $database |
||
108 | * |
||
109 | * @return PMF_System |
||
110 | */ |
||
111 | public function setDatabase(PMF_DB_Driver $database) |
||
117 | |||
118 | /** |
||
119 | * Returns the current version of phpMyFAQ for installation and |
||
120 | * version in the database. |
||
121 | * |
||
122 | * Releases will be numbered with the follow format: |
||
123 | * <major>.<minor>.<patch>[-<prerelease>] |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | public static function getVersion() |
||
146 | |||
147 | /** |
||
148 | * Returns all available templates as array. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function getAvailableTemplates() |
||
165 | |||
166 | /** |
||
167 | * Returns the current API version of phpMyFAQ for installation and |
||
168 | * version in the database. |
||
169 | * |
||
170 | * @return int |
||
171 | */ |
||
172 | public static function getApiVersion() |
||
176 | |||
177 | /** |
||
178 | * Returns the supported databases. |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | public function getSupportedDatabases() |
||
186 | |||
187 | /** |
||
188 | * Returns the locally supported databases. |
||
189 | * |
||
190 | * @param bool $html |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | public function getSupportedSafeDatabases($html = false) |
||
209 | |||
210 | /** |
||
211 | * Checks if the system URI is running with http or https. |
||
212 | * |
||
213 | * @param PMF_Configuration $faqConfig |
||
214 | * |
||
215 | * @return mixed |
||
216 | */ |
||
217 | public function getSystemUri(PMF_Configuration $faqConfig) |
||
233 | |||
234 | /** |
||
235 | * Checks for installed database extensions, if the first supported |
||
236 | * extension is enabled, return true. |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | public function checkDatabase() |
||
250 | |||
251 | /** |
||
252 | * Checks for required PHP extensions. |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function checkRequiredExtensions() |
||
270 | |||
271 | /** |
||
272 | * Checks for an installed phpMyFAQ version. |
||
273 | * |
||
274 | * inc/data.php -> phpMyFAQ 2.0 and 2.5 |
||
275 | * config/database.php -> phpMyFAQ 2.6 and later |
||
276 | * |
||
277 | * @return bool |
||
278 | */ |
||
279 | public function checkphpMyFAQInstallation() |
||
287 | |||
288 | /** |
||
289 | * Returns all missing extensions. |
||
290 | * |
||
291 | * @return array |
||
292 | */ |
||
293 | public function getMissingExtensions() |
||
297 | |||
298 | /** |
||
299 | * Returns true or false on SQLite3. |
||
300 | * |
||
301 | * @static |
||
302 | * |
||
303 | * @param string $dbType |
||
304 | * |
||
305 | * @return bool |
||
306 | */ |
||
307 | public static function isSqlite($dbType) |
||
311 | |||
312 | /** |
||
313 | * Creates a JSON object with all .php files of phpMyFAQ with their sha1 hashes. |
||
314 | * |
||
315 | * @return string |
||
316 | */ |
||
317 | public function createHashes() |
||
356 | |||
357 | // |
||
358 | // Methods to clean a phpMyFAQ installation |
||
359 | // |
||
360 | |||
361 | /** |
||
362 | * Drops all given tables |
||
363 | * @param array $queries |
||
364 | */ |
||
365 | public function dropTables(Array $queries) |
||
373 | |||
374 | /** |
||
375 | * Removes the database.php and the ldap.php if an installation failed. |
||
376 | */ |
||
377 | public function cleanInstallation() |
||
388 | |||
389 | /** |
||
390 | * Print out the HTML5 Footer. |
||
391 | * |
||
392 | * @param bool $onePageBack |
||
393 | */ |
||
394 | public static function renderFooter($onePageBack = false) |
||
408 | } |
||
409 |