Complex classes like Modules 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 Modules, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | final class Modules extends \SimpleSAML\Module\monitor\TestSuiteFactory |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $requiredApacheModules = array(); |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | private $requiredPhpModules = array(); |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | // Important!! Modules-names are handled case-sensitive!! |
||
25 | private $storeApacheDependencies = array(); |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $storePhpDependencies = array( |
||
31 | 'memcache' => 'memcached|memcache', |
||
32 | 'phpsession' => 'session', |
||
33 | 'redis' => 'redis', |
||
34 | 'redissentinel' => 'redis', |
||
35 | 'riak:Store' => 'riak', |
||
36 | 'sql' => 'PDO' |
||
37 | ); |
||
38 | |||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | private $moduleApacheDependencies = array( |
||
43 | 'negotiateext' => 'mod_auth_kerb|mod_auth_gssapi' |
||
44 | ); |
||
45 | |||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | private $modulePhpDependencies = array( |
||
50 | 'authfacebook' => array('curl', 'json'), |
||
51 | 'authYubiKey' => 'curl', |
||
52 | // TODO: consent only requires pdo when database backend is used.. Should probably add this to required-list when processing metadata |
||
53 | // 'consent' => 'PDO', |
||
54 | 'consentAdmin' => 'PDO', |
||
55 | 'ldap' => 'ldap', |
||
56 | 'memcacheMonitor' => 'memcached|memcache', |
||
57 | 'negotiate' => 'krb5', |
||
58 | 'radius' => 'radius', |
||
59 | 'riak' => 'riak', |
||
60 | 'sqlauth' => 'PDO' |
||
61 | ); |
||
62 | |||
63 | /** |
||
64 | * @param TestConfiguration|null $configuration |
||
65 | */ |
||
66 | public function __construct($configuration = null) |
||
70 | |||
71 | /** |
||
72 | * @return void |
||
73 | */ |
||
74 | protected function initialize() |
||
80 | |||
81 | /** |
||
82 | * @return void |
||
83 | */ |
||
84 | private function addRequiredApacheModule($module) |
||
90 | |||
91 | /** |
||
92 | * @return void |
||
93 | */ |
||
94 | private function addRequiredPhpModule($module) |
||
100 | |||
101 | /** |
||
102 | * @return void |
||
103 | */ |
||
104 | private function setRequiredApacheModules() |
||
122 | |||
123 | /** |
||
124 | * @return void |
||
125 | */ |
||
126 | private function setRequiredPhpModules() |
||
148 | |||
149 | /** |
||
150 | * @return void |
||
151 | */ |
||
152 | private function setRequiredSspModules() |
||
172 | |||
173 | /** |
||
174 | * @return string[] |
||
175 | */ |
||
176 | public function getAvailableApacheModules() |
||
181 | |||
182 | /** |
||
183 | * @return string[] |
||
184 | */ |
||
185 | public function getAvailablePhpModules() |
||
190 | |||
191 | /** |
||
192 | * @return array<string,array> |
||
193 | */ |
||
194 | private function getRequiredModules() |
||
198 | |||
199 | /** |
||
200 | * @return array<string,array> |
||
201 | */ |
||
202 | private function getModuleDependencies() |
||
206 | |||
207 | /** |
||
208 | * @return void |
||
209 | */ |
||
210 | protected function invokeTestSuite() |
||
257 | |||
258 | /** |
||
259 | * @param TestData $testData |
||
260 | * @param string $category |
||
261 | * @param array $dependencies |
||
262 | * @param array $output |
||
263 | * |
||
264 | * @return void |
||
265 | */ |
||
266 | private function testRequirement($testData, $category, $dependencies, &$output) |
||
291 | } |
||
292 |