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