Passed
Branch monitor-2.5.x (1a1f16)
by Tim
03:17
created

Connection::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Database;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Modules\Monitor\State 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...
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class Connection extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var \SimpleSAML\Database
13
     */
14
    private $db = null;
15
16
    /**
17
     * @var string
18
     */
19
    private $dsn;
20
21
    /*
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $this->dsn = $testData->getInputItem('dsn');
29
        parent::initialize($testData);
30
    }
31
32
    /*
33
     * @return void
34
     */
35
    public function invokeTest()
36
    {
37
        try {
38
            $this->db = \SimpleSAML\Database::getInstance();
39
        } catch (\Exception $error) {
40
            // Fallthru
41
        }
42
43
        $testResult = new TestResult('Database connection', $this->dsn);
44
45
        if (isSet($error)) {
46
            $testResult->setState(State::WARNING);
47
            $testResult->setMessage($error->getMessage());
48
        } else if (!is_null($this->db)) {
49
            $testResult->setState(State::OK);
50
            $testResult->setMessage('Connection established');
51
            $testResult->addOutput($this->db, 'db');
52
        } else { // Shoud never happen
53
            $testResult->setState(State::WARNING);
54
            $testResult->setMessage("Something went wrong and we couldn't tell why");
55
        }
56
57
        $this->setTestResult($testResult);
58
    }
59
}
60