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 | * @param TestData $testData |
||
|
|||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | protected function initialize($testData = null) |
||
82 | |||
83 | /** |
||
84 | * @return void |
||
85 | */ |
||
86 | private function addRequiredApacheModule($module) |
||
92 | |||
93 | /** |
||
94 | * @return void |
||
95 | */ |
||
96 | private function addRequiredPhpModule($module) |
||
102 | |||
103 | /** |
||
104 | * @return void |
||
105 | */ |
||
106 | private function setRequiredApacheModules() |
||
124 | |||
125 | /** |
||
126 | * @return void |
||
127 | */ |
||
128 | private function setRequiredPhpModules() |
||
150 | |||
151 | /** |
||
152 | * @return void |
||
153 | */ |
||
154 | private function setRequiredSspModules() |
||
174 | |||
175 | /** |
||
176 | * @return array<string,array> |
||
177 | */ |
||
178 | public function getAvailableModules() |
||
179 | { |
||
180 | $configuration = $this->getConfiguration(); |
||
181 | return array( |
||
182 | 'Apache' => $configuration->getAvailableApacheModules(), |
||
183 | 'Php' => $configuration->getAvailablePhpModules() |
||
184 | ); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return array<string,array> |
||
189 | */ |
||
190 | private function getRequiredModules() |
||
194 | |||
195 | /** |
||
196 | * @return array<string,array> |
||
197 | */ |
||
198 | private function getModuleDependencies() |
||
202 | |||
203 | /** |
||
204 | * @return void |
||
205 | */ |
||
206 | protected function invokeTestSuite() |
||
236 | |||
237 | /** |
||
238 | * @param array $output |
||
239 | * |
||
240 | * @return void |
||
241 | */ |
||
242 | protected function calculateState($output) |
||
263 | |||
264 | /** |
||
265 | * @param TestData $testData |
||
266 | * @param string $category |
||
267 | * @param array $dependencies |
||
268 | * @param array $output |
||
269 | * |
||
270 | * @return void |
||
271 | */ |
||
272 | private function testRequirement($testData, $category, $dependencies, &$output) |
||
297 | } |
||
298 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.