Completed
Push — master ( c8a4bf...aca71e )
by Tim
01:38
created

Bind::invokeTest()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
c 5
b 0
f 0
nc 6
nop 0
dl 0
loc 27
rs 8.5806
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
use \SimpleSAML\Module\monitor\TestResult as TestResult;
8
9
final class Bind extends \SimpleSAML\Module\monitor\TestCaseFactory
10
{
11
    /*
12
     * @var \SimpleSAML_Auth_LDAP|null
13
     */
14
    private $connection = null;
15
16
    /*
17
     * @var string|null
18
     */
19
    private $username = null;
20
21
    /*
22
     * @var string|null
23
     */
24
25
    private $password = null;
26
27
28
    /*
29
     * @param TestData $testData
30
     *
31
     * @return void
32
     */
33
    protected function initialize($testData)
34
    {
35
        $this->connection = $testData->getInput('connection');
36
        $authSourceData = $testData->getInput('authSourceData');
37
38
        $this->username = $authSourceData['search.username'];
39
        $this->password = $authSourceData['search.password'];
40
41
        parent::initialize($testData);
42
    }
43
44
   
45
    /*
46
     * @return void
47
     */
48
    protected function invokeTest()
49
    {
50
        $testResult = new TestResult('LDAP Bind', $this->username);
51
        $connection = $this->connection;
52
53
        try {
54
            $bind = $connection->bind($this->username, $this->password);
55
        } catch (\Exception $e) {
56
            // Fallthru
57
        }
58
59
        if (isSet($error)) {
0 ignored issues
show
Bug introduced by
The variable $error seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
60
            $msg = str_replace('Library - LDAP bind(): ', '', $error->getMessage());
61
            $state = State::FATAL;
62
        } elseif ($bind === true) {
63
            $msg = 'Bind succesful';
64
            $state = State::OK;
65
        } else {
66
            $msg = ldap_error($connection).' ('.ldap_errno($connection).')';
67
            $state = State::ERROR;
68
        }
69
70
        $testResult->setMessage($msg);
71
        $testResult->setState($state);
72
73
        $this->setTestResult($testResult);
74
    }
75
}
76