Conditions | 26 |
Paths | 470 |
Total Lines | 136 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
92 | public function getconsent(Request $request) |
||
93 | { |
||
94 | $this->logger::info('Consent - getconsent: Accessing consent interface'); |
||
95 | |||
96 | $stateId = $request->query->get('StateId'); |
||
97 | if ($stateId === null) { |
||
98 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
99 | } |
||
100 | |||
101 | $state = $this->authState::loadState($stateId, 'consent:request'); |
||
102 | |||
103 | if (is_null($state)) { |
||
104 | throw new Error\NoState(); |
||
105 | } elseif (array_key_exists('core:SP', $state)) { |
||
106 | $spentityid = $state['core:SP']; |
||
107 | } elseif (array_key_exists('saml:sp:State', $state)) { |
||
108 | $spentityid = $state['saml:sp:State']['core:SP']; |
||
109 | } else { |
||
110 | $spentityid = 'UNKNOWN'; |
||
111 | } |
||
112 | |||
113 | // The user has pressed the yes-button |
||
114 | if ($request->query->get('yes') !== null) { |
||
115 | if ($request->query->get('saveconsent') !== null) { |
||
116 | $this->logger::stats('consentResponse remember'); |
||
117 | } else { |
||
118 | $this->logger::stats('consentResponse rememberNot'); |
||
119 | } |
||
120 | |||
121 | $statsInfo = [ |
||
122 | 'remember' => $request->query->get('saveconsent'), |
||
123 | ]; |
||
124 | if (isset($state['Destination']['entityid'])) { |
||
125 | $statsInfo['spEntityID'] = $state['Destination']['entityid']; |
||
126 | } |
||
127 | Stats::log('consent:accept', $statsInfo); |
||
128 | |||
129 | if ( |
||
130 | array_key_exists('consent:store', $state) |
||
131 | && $request->query->get('saveconsent') === '1' |
||
132 | ) { |
||
133 | // Save consent |
||
134 | $store = $state['consent:store']; |
||
135 | $userId = $state['consent:store.userId']; |
||
136 | $targetedId = $state['consent:store.destination']; |
||
137 | $attributeSet = $state['consent:store.attributeSet']; |
||
138 | |||
139 | $this->logger::debug( |
||
140 | 'Consent - saveConsent() : [' . $userId . '|' . $targetedId . '|' . $attributeSet . ']' |
||
141 | ); |
||
142 | try { |
||
143 | $store->saveConsent($userId, $targetedId, $attributeSet); |
||
144 | } catch (Exception $e) { |
||
145 | $this->logger::error('Consent: Error writing to storage: ' . $e->getMessage()); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | return new RunnableResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]); |
||
150 | } |
||
151 | |||
152 | // Prepare attributes for presentation |
||
153 | $attributes = $state['Attributes']; |
||
154 | $noconsentattributes = $state['consent:noconsentattributes']; |
||
155 | |||
156 | // Remove attributes that do not require consent |
||
157 | foreach ($attributes as $attrkey => $attrval) { |
||
158 | if (in_array($attrkey, $noconsentattributes, true)) { |
||
159 | unset($attributes[$attrkey]); |
||
160 | } |
||
161 | } |
||
162 | $para = [ |
||
163 | 'attributes' => &$attributes |
||
164 | ]; |
||
165 | |||
166 | // Reorder attributes according to attributepresentation hooks |
||
167 | Module::callHooks('attributepresentation', $para); |
||
168 | |||
169 | // Unset the values for attributes that need to be hidden |
||
170 | if (array_key_exists('consent:hiddenAttributes', $state)) { |
||
171 | foreach ($state['consent:hiddenAttributes'] as $hidden) { |
||
172 | if (array_key_exists($hidden, $attributes)) { |
||
173 | $attributes[$hidden] = null; |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
178 | // Make, populate and layout consent form |
||
179 | $t = new Template($this->config, 'consent:consentform.twig'); |
||
180 | $translator = $t->getTranslator(); |
||
|
|||
181 | $t->data['attributes'] = $attributes; |
||
182 | $t->data['checked'] = $state['consent:checked']; |
||
183 | $t->data['stateId'] = $stateId; |
||
184 | $t->data['source'] = $state['Source']; |
||
185 | $t->data['destination'] = $state['Destination']; |
||
186 | |||
187 | // Fetch privacy policy |
||
188 | if ( |
||
189 | array_key_exists('UIInfo', $state['Destination']) && |
||
190 | array_key_exists('PrivacyStatementURL', $state['Destination']['UIInfo']) && |
||
191 | (!empty($state['Destination']['UIInfo']['PrivacyStatementURL'])) |
||
192 | ) { |
||
193 | $privacypolicy = reset($state['Destination']['UIInfo']['PrivacyStatementURL']); |
||
194 | } elseif ( |
||
195 | array_key_exists('UIInfo', $state['Source']) && |
||
196 | array_key_exists('PrivacyStatementURL', $state['Source']['UIInfo']) && |
||
197 | (!empty($state['Source']['UIInfo']['PrivacyStatementURL'])) |
||
198 | ) { |
||
199 | $privacypolicy = reset($state['Source']['UIInfo']['PrivacyStatementURL']); |
||
200 | } else { |
||
201 | $privacypolicy = false; |
||
202 | } |
||
203 | if ($privacypolicy !== false) { |
||
204 | $privacypolicy = str_replace( |
||
205 | '%SPENTITYID%', |
||
206 | urlencode($spentityid), |
||
207 | $privacypolicy |
||
208 | ); |
||
209 | } |
||
210 | $t->data['sppp'] = $privacypolicy; |
||
211 | |||
212 | // Set focus element |
||
213 | switch ($state['consent:focus']) { |
||
214 | case 'yes': |
||
215 | $t->data['autofocus'] = 'yesbutton'; |
||
216 | break; |
||
217 | case 'no': |
||
218 | $t->data['autofocus'] = 'nobutton'; |
||
219 | break; |
||
220 | case null: |
||
221 | default: |
||
222 | break; |
||
223 | } |
||
224 | |||
225 | $t->data['usestorage'] = array_key_exists('consent:store', $state); |
||
226 | |||
227 | return $t; |
||
228 | } |
||
323 |