Passed
Pull Request — master (#6)
by Tim
12:09
created

DateTimeTrait::validDateTime()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
rs 10
cc 3
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\Assert;
6
7
use SimpleSAML\Assert\AssertionFailedException;
8
use SimpleSAML\SAML11\Exception\ProtocolViolationException;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * @package simplesamlphp/saml11
13
 */
14
trait DateTimeTrait
15
{
16
    /**
17
     * @param string $value
18
     * @param string $message
19
     */
20
    protected static function validDateTime(string $value, string $message = ''): void
21
    {
22
        parent::validDateTime($value, $message);
23
24
        try {
25
            /**
26
             * 1.2.2 Time Values
27
             *
28
             * All SAML time values have the type xsd:dateTime, which is built in to the W3C XML Schema Datatypes
29
             * specification [Schema2], and MUST be expressed in UTC form
30
             */
31
            static::endsWith(
32
                $value,
33
                'Z',
34
                $message ?: '%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.',
35
            );
36
        } catch (AssertionFailedException $e) {
37
            throw new ProtocolViolationException($e->getMessage());
38
        }
39
    }
40
}
41