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