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