Conditions | 10 |
Paths | 52 |
Total Lines | 86 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
139 | public function edit(Request $request): Template |
||
140 | { |
||
141 | $authsource = $this->moduleConfig->getValue('auth', 'login-admin'); |
||
142 | $useridattr = $this->moduleConfig->getValue('useridattr', 'eduPersonPrincipalName'); |
||
143 | |||
144 | $as = new $this->authSimple($authsource); |
||
145 | $as->requireAuth(); |
||
146 | |||
147 | $attributes = $as->getAttributes(); |
||
148 | // Check if userid exists |
||
149 | if (!isset($attributes[$useridattr])) { |
||
150 | throw new Error\Exception('User ID is missing'); |
||
151 | } |
||
152 | $userid = $attributes[$useridattr][0]; |
||
153 | |||
154 | $entityId = $request->get('entityid'); |
||
155 | $xmlMetadata = $request->get('xmlmetadata'); |
||
156 | |||
157 | $mdh = new Metadata\MetaDataStorageHandlerSerialize($this->moduleConfig->getArray('metahandlerConfig', [])); |
||
158 | |||
159 | if ($entityId !== null) { |
||
160 | $metadata = $mdh->getMetadata($entityId, 'saml20-sp-remote'); |
||
161 | $this->requireOwnership($metadata, $userid); |
||
162 | } elseif ($xmlMetadata !== null) { |
||
163 | $xmlUtils = new Utils\XML(); |
||
164 | $xmlUtils->checkSAMLMessage($xmlMetadata, 'saml-meta'); |
||
165 | $entities = Metadata\SAMLParser::parseDescriptorsString($xmlMetadata); |
||
166 | $entity = array_pop($entities); |
||
167 | $metadata = $entity->getMetadata20SP(); |
||
168 | |||
169 | /* Trim metadata endpoint arrays. */ |
||
170 | $metadata['AssertionConsumerService'] = [ |
||
171 | Utils\Config\Metadata::getDefaultEndpoint( |
||
172 | $metadata['AssertionConsumerService'], |
||
173 | [Constants::BINDING_HTTP_POST] |
||
174 | ) |
||
175 | ]; |
||
176 | $metadata['SingleLogoutService'] = [ |
||
177 | Utils\Config\Metadata::getDefaultEndpoint( |
||
178 | $metadata['SingleLogoutService'], |
||
179 | [Constants::BINDING_HTTP_REDIRECT] |
||
180 | ) |
||
181 | ]; |
||
182 | } else { |
||
183 | $metadata = [ |
||
184 | 'owner' => $userid, |
||
185 | ]; |
||
186 | } |
||
187 | |||
188 | $editor = new Editor(); |
||
189 | |||
190 | if ($request->get('submit')) { |
||
191 | $editor->checkForm($request->request->all()); |
||
192 | $metadata = $editor->formToMeta($request->request->all(), [], ['owner' => $userid]); |
||
193 | $wasEntityId = $request->get('was-entityid'); |
||
194 | if (($wasEntityId !== null) && ($wasEntityId !== $metadata['entityid'])) { |
||
195 | $premetadata = $mdh->getMetadata($wasEntityId, 'saml20-sp-remote'); |
||
196 | $this->requireOwnership($premetadata, $userid); |
||
197 | $mdh->deleteMetadata($wasEntityId, 'saml20-sp-remote'); |
||
198 | } |
||
199 | |||
200 | try { |
||
201 | $testmetadata = $mdh->getMetadata($metadata['entityid'], 'saml20-sp-remote'); |
||
202 | } catch (Exception $e) { |
||
203 | // catch |
||
204 | $testmetadata = null; |
||
205 | } |
||
206 | |||
207 | if ($testmetadata) { |
||
208 | $this->requireOwnership($testmetadata, $userid); |
||
209 | } |
||
210 | |||
211 | $result = $mdh->saveMetadata($metadata['entityid'], 'saml20-sp-remote', $metadata); |
||
212 | if ($result === false) { |
||
213 | throw new Error\Exception("Could not save metadata. See log for details"); |
||
214 | } |
||
215 | |||
216 | return new Template($this->config, 'metaedit:saved.twig'); |
||
217 | } |
||
218 | |||
219 | $form = $editor->metaToForm($metadata); |
||
220 | |||
221 | $t = new Template($this->config, 'metaedit:formedit.twig'); |
||
222 | $t->data['form'] = $form; |
||
223 | |||
224 | return $t; |
||
225 | } |
||
258 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.