Total Complexity | 42 |
Total Lines | 287 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like ConsentController 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.
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 ConsentController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class ConsentController |
||
28 | { |
||
29 | /** @var \SimpleSAML\Configuration */ |
||
30 | protected $config; |
||
31 | |||
32 | /** @var \SimpleSAML\Session */ |
||
33 | protected $session; |
||
34 | |||
35 | /** |
||
36 | * @var \SimpleSAML\Auth\State|string |
||
37 | * @psalm-var \SimpleSAML\Auth\State|class-string |
||
38 | */ |
||
39 | protected $authState = Auth\State::class; |
||
40 | |||
41 | /** |
||
42 | * @var \SimpleSAML\Logger|string |
||
43 | * @psalm-var \SimpleSAML\Logger|class-string |
||
44 | */ |
||
45 | protected $logger = Logger::class; |
||
46 | |||
47 | |||
48 | /** |
||
49 | * ConsentController constructor. |
||
50 | * |
||
51 | * @param \SimpleSAML\Configuration $config The configuration to use. |
||
52 | * @param \SimpleSAML\Session $session The current user session. |
||
53 | */ |
||
54 | public function __construct(Configuration $config, Session $session) |
||
55 | { |
||
56 | $this->config = $config; |
||
57 | $this->session = $session; |
||
58 | } |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Inject the \SimpleSAML\Auth\State dependency. |
||
63 | * |
||
64 | * @param \SimpleSAML\Auth\State $authState |
||
65 | */ |
||
66 | public function setAuthState(Auth\State $authState): void |
||
67 | { |
||
68 | $this->authState = $authState; |
||
69 | } |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Inject the \SimpleSAML\Logger dependency. |
||
74 | * |
||
75 | * @param \SimpleSAML\Logger $logger |
||
76 | */ |
||
77 | public function setLogger(Logger $logger): void |
||
78 | { |
||
79 | $this->logger = $logger; |
||
80 | } |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Display consent form. |
||
85 | * |
||
86 | * @param \Symfony\Component\HttpFoundation\Request $request The current request. |
||
87 | * |
||
88 | * @return \SimpleSAML\XHTML\Template|\SimpleSAML\HTTP\RunnableResponse |
||
89 | */ |
||
90 | public function getconsent(Request $request) |
||
233 | } |
||
234 | |||
235 | |||
236 | /** |
||
237 | * @param \Symfony\Component\HttpFoundation\Request $request The current request. |
||
238 | * |
||
239 | * @return \SimpleSAML\XHTML\Template |
||
240 | */ |
||
241 | public function noconsent(Request $request): Template |
||
282 | } |
||
283 | |||
284 | |||
285 | /** |
||
286 | * @param \Symfony\Component\HttpFoundation\Request $request The current request. |
||
287 | * |
||
288 | * @return \SimpleSAML\HTTP\RunnableResponse |
||
289 | */ |
||
290 | public function logout(Request $request): RunnableResponse |
||
291 | { |
||
292 | $stateId = $request->query->get('StateId', null); |
||
293 | if ($stateId === null) { |
||
294 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
295 | } |
||
296 | |||
297 | $state = $this->authState::loadState($stateId, 'consent:request'); |
||
298 | if (is_null($state)) { |
||
299 | throw new Error\NoState(); |
||
300 | } |
||
301 | $state['Responder'] = ['\SimpleSAML\Module\consent\Logout', 'postLogout']; |
||
302 | |||
303 | $idp = IdP::getByState($state); |
||
304 | return new RunnableResponse([$idp, 'handleLogoutRequest'], [&$state, $stateId]); |
||
305 | } |
||
306 | |||
307 | |||
308 | /** |
||
309 | * @return \SimpleSAML\XHTML\Template |
||
310 | */ |
||
311 | public function logoutcompleted(): Template |
||
314 | } |
||
315 | } |
||
316 |