| Conditions | 6 |
| Paths | 3 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 59 | public function invokeTest() |
||
| 60 | { |
||
| 61 | // Test LDAP configuration |
||
| 62 | $confTest = new TestCase\AuthSource\Ldap\Configuration( |
||
| 63 | new TestData(['authSourceData' => $this->authSourceData]) |
||
| 64 | ); |
||
| 65 | $confTestResult = $confTest->getTestResult(); |
||
| 66 | $this->addTestResult($confTestResult); |
||
| 67 | |||
| 68 | if ($confTestResult->getState() === State::OK) { |
||
| 69 | $connection = $confTestResult->getOutput('connection'); |
||
| 70 | |||
| 71 | // Test connection for each configured LDAP-server |
||
| 72 | foreach ($this->hosts as $hostname) { |
||
| 73 | $preparedTestData = $this->prepareConnection($hostname, $this->authSourceData, $this->authSourceSpecifics); |
||
| 74 | $connTest = new TestCase\Network\ConnectUri( |
||
| 75 | new TestData($preparedTestData) |
||
| 76 | ); |
||
| 77 | $connTestResult = $connTest->getTestResult(); |
||
| 78 | $this->addTestResult($connTestResult); |
||
| 79 | |||
| 80 | if ($connTestResult->getState() === State::OK) { |
||
| 81 | $certData = $connTestResult->getOutput('certData'); |
||
| 82 | |||
| 83 | // Test certificate when available |
||
| 84 | if ($certData !== null) { |
||
| 85 | $certTest = new TestCase\Cert( |
||
| 86 | new TestData([ |
||
| 87 | 'certData' => $certData, |
||
| 88 | 'category' => 'LDAP Server Certificate', |
||
| 89 | 'certExpirationWarning' => $this->certExpirationWarning, |
||
| 90 | ]) |
||
| 91 | ); |
||
| 92 | $certTestResult = $certTest->getTestResult(); |
||
| 93 | $this->addTestResult($certTestResult); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // Test bind |
||
| 99 | $testData = new TestData([ |
||
| 100 | 'authSourceData' => $this->authSourceData, |
||
| 101 | 'connection' => $connection |
||
| 102 | ]); |
||
| 103 | $bindTest = new TestCase\AuthSource\Ldap\Bind( |
||
| 104 | $testData |
||
| 105 | ); |
||
| 106 | $bindTestResult = $bindTest->getTestResult(); |
||
| 107 | $this->addTestResult($bindTestResult); |
||
| 108 | |||
| 109 | if ($bindTestResult->getState() === State::OK) { |
||
| 110 | // Test search |
||
| 111 | $testData = new TestData([ |
||
| 112 | 'authSourceData' => $this->authSourceData, |
||
| 113 | 'connection' => $connection |
||
| 114 | ]); |
||
| 115 | |||
| 116 | $searchTest = new TestCase\AuthSource\Ldap\Search( |
||
| 117 | $testData |
||
| 118 | ); |
||
| 119 | $searchTestResult = $searchTest->getTestResult(); |
||
| 120 | $this->addTestResult($searchTestResult); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $state = $this->calculateState(); |
||
| 125 | |||
| 126 | $testResult = new TestResult('LDAP Authentication'); |
||
| 127 | $testResult->setState($state); |
||
| 128 | $this->setTestResult($testResult); |
||
| 129 | } |
||
| 166 |