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