| Conditions | 7 | 
| Paths | 11 | 
| Total Lines | 62 | 
| Code Lines | 45 | 
| 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 | ||
| 48 | public function invokeTest(): void | ||
| 49 |     { | ||
| 50 |         if ($this->checkAuthSources === true) { | ||
| 51 | $authSources = $this->authSourceConfig->getOptions(); | ||
| 52 |         } elseif (is_array($this->checkAuthSources)) { | ||
| 53 | $authSources = array_intersect($this->authSourceConfig->getOptions(), $this->checkAuthSources); | ||
| 54 |         } else { // false or invalid value | ||
| 55 |             $testResult = new TestResult('Authentication sources'); | ||
| 56 | $testResult->setState(State::NOSTATE); | ||
| 57 | $this->setTestResult($testResult); | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | $configuration = $this->getConfiguration(); | ||
| 62 | $output = []; | ||
| 63 | |||
| 64 |         foreach ($authSources as $authSourceId) { | ||
| 65 | $authSourceSpecifics = $this->getAuthSourceSpecifics($authSourceId); | ||
| 66 | $authSourceData = $this->authSourceConfig->getValue($authSourceId); | ||
| 67 | $input = [ | ||
| 68 | 'authSourceId' => $authSourceId, | ||
| 69 | 'authSourceData' => $this->authSourceConfig->getValue($authSourceId), | ||
| 70 | 'authSourceSpecifics' => $authSourceSpecifics, | ||
| 71 | ]; | ||
| 72 | $testData = new TestData($input); | ||
| 73 | |||
| 74 |             switch ($authSourceData[0]) { | ||
| 75 | case 'ldap:Ldap': | ||
| 76 | $ldapTest = new AuthSource\Ldap($configuration, $testData); | ||
| 77 | $this->addTestResults($ldapTest->getTestResults()); | ||
| 78 | $output[$authSourceId] = $ldapTest->getArrayizeTestResults(); | ||
| 79 | break; | ||
| 80 | case 'negotiate:Negotiate': | ||
| 81 | $negoTest = new AuthSource\Negotiate($configuration, $testData); | ||
| 82 | $this->addTestResults($negoTest->getTestResults()); | ||
| 83 | |||
| 84 | // We need to do some convertions from Negotiate > LDAP | ||
| 85 | $authSourceData = $this->authSourceConfig->getValue($authSourceData['fallback']); | ||
| 86 | $testData->setInput($authSourceData, 'authSourceData'); | ||
| 87 | |||
| 88 | $ldapTest = new AuthSource\Ldap($configuration, $testData); | ||
| 89 | $this->addTestResults($ldapTest->getTestResults()); | ||
| 90 | |||
| 91 | $output[$authSourceId] = array_merge( | ||
| 92 | $negoTest->getArrayizeTestResults(), | ||
| 93 | $ldapTest->getArrayizeTestResults() | ||
| 94 | ); | ||
| 95 | break; | ||
| 96 | case 'multiauth:MultiAuth': | ||
| 97 | // Relies on other authSources | ||
| 98 | continue 2; | ||
| 99 | default: | ||
| 100 | // Not implemented | ||
| 101 | continue 2; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | $state = $this->calculateState(); | ||
| 106 |         $testResult = new TestResult('Authentication sources'); | ||
| 107 | $testResult->setState($state); | ||
| 108 | $testResult->setOutput($output); | ||
| 109 | $this->setTestResult($testResult); | ||
| 110 | } | ||
| 128 |