Passed
Push — master ( 765b41...e6bf79 )
by Tim
03:49 queued 01:38
created

SAMLDateTimeTrait::validSAMLDateTime()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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