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