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 $authenticatedAttribute |
||
96 | * @param string $logoutUrlAttribute |
||
97 | * @param array $authenticationRequirements |
||
98 | * @param string $defaultCharset |
||
99 | */ |
||
100 | public function __construct( |
||
130 | |||
131 | /** |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isSecuredHandler() |
||
138 | |||
139 | /** |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getHandlerPath() |
||
146 | |||
147 | /** |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getSessionLoginPath() |
||
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | */ |
||
158 | public function getSessionLogoutPath() |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getSessionOverviewPath() |
||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | public function getStatusPath() |
||
178 | |||
179 | /** |
||
180 | * @return Request |
||
181 | */ |
||
182 | protected function getRequest() |
||
190 | |||
191 | /** |
||
192 | * @param null $fallback |
||
193 | * @return array |
||
194 | */ |
||
195 | public function getAttributes($fallback = null) |
||
204 | |||
205 | /** |
||
206 | * @param string $name |
||
207 | * @param null $fallback |
||
208 | * @return null|string |
||
209 | */ |
||
210 | public function getAttribute($name, $fallback = null) |
||
215 | |||
216 | /** |
||
217 | * @param string $name |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function hasAttribute($name) |
||
225 | |||
226 | /** |
||
227 | * @param array $keyValues |
||
228 | * @return bool |
||
229 | */ |
||
230 | public function hasAttributeValues(array $keyValues) |
||
253 | |||
254 | /** |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function isAuthenticated() |
||
265 | |||
266 | /** |
||
267 | * @return string |
||
268 | */ |
||
269 | public function getUsername() |
||
273 | |||
274 | /** |
||
275 | * @param $username |
||
276 | * @return array |
||
277 | */ |
||
278 | public function getAttributesByUsername($username) |
||
286 | |||
287 | /** |
||
288 | * Returns shibboleth session URL |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getHandlerUrl() |
||
297 | |||
298 | /** |
||
299 | * Returns URL to initiate login session. After successful login, the user will be redirected |
||
300 | * to the optional target page. The target can be an absolute or relative URL. |
||
301 | * |
||
302 | * @param string|null $target URL to redirect to after successful login. Defaults to the current request URL. |
||
303 | * @return string The absolute URL to initiate a session |
||
304 | */ |
||
305 | public function getLoginUrl($target = null) |
||
313 | |||
314 | /** |
||
315 | * Returns URL to invalidate the shibboleth session. |
||
316 | * |
||
317 | * @param null $target URL to redirect to after successful logout. Defaults to the current request URL. |
||
318 | * @return string |
||
319 | */ |
||
320 | public function getLogoutUrl($target = null) |
||
333 | |||
334 | /** |
||
335 | * Returns URL to show session. |
||
336 | * |
||
337 | * @return string The absolute URL to show a session |
||
338 | */ |
||
339 | public function getOverviewUrl() |
||
343 | |||
344 | /** |
||
345 | * Returns URL to show status. |
||
346 | * |
||
347 | * @return string The absolute URL to show the status |
||
348 | */ |
||
349 | public function getStatusUrl() |
||
353 | |||
354 | /** |
||
355 | * @deprecated |
||
356 | * @return string |
||
357 | */ |
||
358 | public function getSessionInitiatorPath() |
||
362 | |||
363 | /** |
||
364 | * @return string |
||
365 | */ |
||
366 | public function getUsernameAttribute() |
||
370 | |||
371 | /** |
||
372 | * @return string |
||
373 | */ |
||
374 | public function getAuthenticatedAttribute() |
||
378 | |||
379 | /** |
||
380 | * @return string |
||
381 | */ |
||
382 | public function getLogoutUrlAttribute() |
||
386 | |||
387 | /** |
||
388 | * @return string |
||
389 | */ |
||
390 | public function getAuthenticationRequirements() |
||
394 | |||
395 | /** |
||
396 | * @return string |
||
397 | */ |
||
398 | public function getDefaultCharset() |
||
402 | |||
403 | /** |
||
404 | * @param null|string $url |
||
405 | * @return bool |
||
406 | */ |
||
407 | public function isReachable($url = null) |
||
428 | } |
||
429 |