Bind   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 9 1
A invokeTest() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap;
6
7
use Exception;
8
use SimpleSAML\Configuration;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, SimpleSAML\Module\monito...urce\Ldap\Configuration. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use SimpleSAML\Module\ldap\ConnectorInterface;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\ldap\ConnectorInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SimpleSAML\Module\monitor\State;
11
use SimpleSAML\Module\monitor\TestData;
12
use SimpleSAML\Module\monitor\TestResult;
13
14
use function str_replace;
15
16
final class Bind extends \SimpleSAML\Module\monitor\TestCaseFactory
17
{
18
    /** @var \SimpleSAML\Module\ldap\ConnectorInterface */
19
    private ConnectorInterface $connection;
20
21
    /** @var string */
22
    private string $username;
23
24
    /** @var string */
25
    private string $password;
26
27
28
    /**
29
     * @param \SimpleSAML\Module\monitor\TestData $testData
30
     *
31
     * @return void
32
     */
33
    protected function initialize(TestData $testData): void
34
    {
35
        $this->connection = $testData->getInputItem('connection');
36
        $authSourceData = $testData->getInputItem('authSourceData');
37
38
        $this->username = $authSourceData->getString('search.username');
39
        $this->password = $authSourceData->getString('search.password');
40
41
        parent::initialize($testData);
42
    }
43
44
45
    /**
46
     * @return void
47
     */
48
    public function invokeTest(): void
49
    {
50
        try {
51
            $bind = $this->connection->bind($this->username, $this->password);
0 ignored issues
show
Unused Code introduced by
The assignment to $bind is dead and can be removed.
Loading history...
52
        } catch (Exception $error) {
53
            // Fallthru
54
        }
55
56
        $testResult = new TestResult('LDAP Bind', $this->username);
57
        if (isset($error)) {
58
            $msg = str_replace('Library - LDAP bind(): ', '', $error->getMessage());
59
            $testResult->setState(State::FATAL);
60
        } else {
61
            $msg = 'Bind succesful';
62
            $testResult->setState(State::OK);
63
        }
64
65
        $testResult->setMessage($msg);
66
        $this->setTestResult($testResult);
67
    }
68
}
69