Complex classes like ShibbolethServiceProvider 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 ShibbolethServiceProvider, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class ShibbolethServiceProvider implements AttributesByUsernameProviderInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var RequestStack |
||
12 | */ |
||
13 | protected $requestStack; |
||
14 | |||
15 | /** |
||
16 | * @var AttributeDefinitionsProviderInterface |
||
17 | */ |
||
18 | protected $attributeDefinitionsProvider; |
||
19 | |||
20 | /** |
||
21 | * @var bool |
||
22 | */ |
||
23 | protected $securedHandler; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $handlerPath; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $statusPath; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $sessionLoginPath; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $sessionLogoutPath; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $sessionOverviewPath; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $usernameAttribute; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $authenticatedAttribute; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $logoutUrlAttribute; |
||
64 | |||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $authenticationRequirements; |
||
69 | |||
70 | /** |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $defaultCharset; |
||
74 | |||
75 | /** |
||
76 | * @var Request |
||
77 | */ |
||
78 | protected $request; |
||
79 | |||
80 | /** |
||
81 | * @var bool |
||
82 | */ |
||
83 | protected $authenticated; |
||
84 | |||
85 | /** |
||
86 | * @param RequestStack $requestStack |
||
87 | * @param AttributeDefinitionsProviderInterface $attributeDefinitionsProvider |
||
88 | * @param bool $securedHandler |
||
89 | * @param string $handlerPath |
||
90 | * @param string $statusPath |
||
91 | * @param string $sessionLoginPath |
||
92 | * @param string $sessionLogoutPath |
||
93 | * @param string $sessionOverviewPath |
||
94 | * @param string $usernameAttribute |
||
95 | * @param string $logoutUrlAttribute |
||
96 | * @param array $authenticationRequirements |
||
97 | * @param string $defaultCharset |
||
98 | */ |
||
99 | public function __construct( |
||
131 | |||
132 | /** |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function isSecuredHandler() |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getHandlerPath() |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getSessionLoginPath() |
||
155 | |||
156 | /** |
||
157 | * @return string |
||
158 | */ |
||
159 | public function getSessionLogoutPath() |
||
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | */ |
||
167 | public function getSessionOverviewPath() |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getStatusPath() |
||
179 | |||
180 | /** |
||
181 | * @return Request |
||
182 | */ |
||
183 | protected function getRequest() |
||
191 | |||
192 | /** |
||
193 | * @param null $fallback |
||
194 | * @return array |
||
195 | */ |
||
196 | public function getAttributes($fallback = null) |
||
205 | |||
206 | /** |
||
207 | * @param string $name |
||
208 | * @param null $fallback |
||
209 | * @return null|string |
||
210 | */ |
||
211 | public function getAttribute($name, $fallback = null) |
||
216 | |||
217 | /** |
||
218 | * @param string $name |
||
219 | * @return bool |
||
220 | */ |
||
221 | public function hasAttribute($name) |
||
226 | |||
227 | /** |
||
228 | * @param array $keyValues |
||
229 | * @return bool |
||
230 | */ |
||
231 | public function hasAttributeValues(array $keyValues) |
||
254 | |||
255 | /** |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function isAuthenticated() |
||
266 | |||
267 | /** |
||
268 | * @return string |
||
269 | */ |
||
270 | public function getUsername() |
||
274 | |||
275 | /** |
||
276 | * @param $username |
||
277 | * @return array |
||
278 | */ |
||
279 | public function getAttributesByUsername($username) |
||
287 | |||
288 | /** |
||
289 | * Returns shibboleth session URL |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function getHandlerUrl() |
||
298 | |||
299 | /** |
||
300 | * Returns URL to initiate login session. After successful login, the user will be redirected |
||
301 | * to the optional target page. The target can be an absolute or relative URL. |
||
302 | * |
||
303 | * @param string|null $target URL to redirect to after successful login. Defaults to the current request URL. |
||
304 | * @return string The absolute URL to initiate a session |
||
305 | */ |
||
306 | public function getLoginUrl($target = null) |
||
314 | |||
315 | /** |
||
316 | * Returns URL to invalidate the shibboleth session. |
||
317 | * |
||
318 | * @param null $target URL to redirect to after successful logout. Defaults to the current request URL. |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getLogoutUrl($target = null) |
||
334 | |||
335 | /** |
||
336 | * Returns URL to show session. |
||
337 | * |
||
338 | * @return string The absolute URL to show a session |
||
339 | */ |
||
340 | public function getOverviewUrl() |
||
344 | |||
345 | /** |
||
346 | * Returns URL to show status. |
||
347 | * |
||
348 | * @return string The absolute URL to show the status |
||
349 | */ |
||
350 | public function getStatusUrl() |
||
354 | |||
355 | /** |
||
356 | * @deprecated |
||
357 | * @return string |
||
358 | */ |
||
359 | public function getSessionInitiatorPath() |
||
363 | |||
364 | /** |
||
365 | * @return string |
||
366 | */ |
||
367 | public function getUsernameAttribute() |
||
371 | |||
372 | /** |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getAuthenticatedAttribute() |
||
379 | |||
380 | /** |
||
381 | * @return string |
||
382 | */ |
||
383 | public function getLogoutUrlAttribute() |
||
387 | |||
388 | /** |
||
389 | * @return string |
||
390 | */ |
||
391 | public function getAuthenticationRequirements() |
||
395 | |||
396 | /** |
||
397 | * @return string |
||
398 | */ |
||
399 | public function getDefaultCharset() |
||
403 | |||
404 | /** |
||
405 | * @param null|string $url |
||
406 | * @return bool |
||
407 | */ |
||
408 | public function isReachable($url = null) |
||
429 | } |
||
430 |