Passed
Branch monitor-2.5.x (32aff2)
by Tim
01:33
created

Sql   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 4 1
A invokeTest() 0 14 2
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Store;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class Sql extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var string|null
13
     */
14
    private $host;
15
16
    /**
17
     * @param TestData $testData
18
     *
19
     * @return void
20
     */
21
    protected function initialize($testData)
22
    {
23
        $this->host = $testData->getInputItem('host');
24
        parent::initialize($testData);
25
    }
26
27
    /**
28
     * @return void
29
     */
30
    public function invokeTest()
31
    {
32
        $testResult = new TestResult('SQL Server Health', $this->host);
33
34
        try {
35
            new \SimpleSAML\Store\SQL();
36
            $testResult->setState(State::OK);
37
            $testResult->setMessage('Connection to the database succesfully established');
38
        } catch (\Exception $e) {
39
            $testResult->setState(State::FATAL);
40
            $testResult->setMessage('Unable to connect to the database; '.$e->getMessage());
41
        }
42
43
        $this->setTestResult($testResult);
44
    }
45
}
46