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

SAMLDateTimeTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validSAMLDateTime() 0 18 3
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