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