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

Expiration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
A invokeTest() 0 19 3
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Metadata;
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 Expiration extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var string
13
     */
14
    private $entityId;
15
16
    /**
17
     * @var array
18
     */
19
    private $metadata;
20
21
    /**
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $this->entityId = $testData->getInputItem('entityId');
29
        $this->metadata = $testData->getInputItem('entityMetadata');
30
31
        parent::initialize($testData);
32
    }
33
34
    /**
35
     * @return void
36
     */
37
    public function invokeTest()
38
    {
39
        $testResult = new TestResult('Metadata expiration', $this->entityId);
40
41
        if (array_key_exists('expire', $this->metadata)) {
42
            $expiration = $this->metadata['expire'];
43
            if ($expiration <= time()) {
44
                $testResult->setState(State::ERROR);
45
                $testResult->setMessage('Metadata has expired');
46
            } else {
47
                $testResult->setState(State::OK);
48
                $testResult->setMessage('Metadata will expire on ' . strftime('%c', $expiration));
49
            }
50
        } else {
51
            $testResult->setState(State::OK);
52
            $testResult->setMessage('Metadata never expires');
53
        }
54
55
        $this->setTestResult($testResult);
56
    }
57
}
58
59