Sql   A
last analyzed

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