Passed
Push — monitor-3.0.x ( f85cdc...51d4ea )
by Tim
03:29
created

Expiration::invokeTest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 0
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase\Metadata;
4
5
use SimpleSAML\Module\monitor\State;
6
use SimpleSAML\Module\monitor\TestData;
7
use SimpleSAML\Module\monitor\TestResult;
8
9
final class Expiration extends \SimpleSAML\Module\monitor\TestCaseFactory
10
{
11
    /** @var string */
12
    private $entityId;
13
14
    /** @var array */
15
    private $metadata;
16
17
18
    /**
19
     * @param \SimpleSAML\Module\monitor\TestData $testData
20
     *
21
     * @return void
22
     */
23
    protected function initialize(TestData $testData): void
24
    {
25
        $this->entityId = $testData->getInputItem('entityId');
26
        $this->metadata = $testData->getInputItem('entityMetadata');
27
28
        parent::initialize($testData);
29
    }
30
31
32
    /**
33
     * @return void
34
     */
35
    public function invokeTest(): void
36
    {
37
        $testResult = new TestResult('Metadata expiration', $this->entityId);
38
        if (array_key_exists('expire', $this->metadata)) {
39
            $expiration = $this->metadata['expire'];
40
            if ($expiration <= time()) {
41
                $testResult->setState(State::ERROR);
42
                $testResult->setMessage('Metadata has expired');
43
            } else {
44
                $testResult->setState(State::OK);
45
                $testResult->setMessage('Metadata will expire on ' . strftime('%c', $expiration));
46
            }
47
        } else {
48
            $testResult->setState(State::OK);
49
            $testResult->setMessage('Metadata never expires');
50
        }
51
52
        $this->setTestResult($testResult);
53
    }
54
}
55