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