Passed
Push — master ( 6d44e6...724433 )
by Tim
02:38
created

RelayStateTrait::validRelayState()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assert;
6
7
use SimpleSAML\Assert\AssertionFailedException;
8
use SimpleSAML\SAML2\Constants as C;
9
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
10
11
/**
12
 * @package simplesamlphp/saml2
13
 */
14
trait RelayStateTrait
15
{
16
    /**
17
     * @param string $value
18
     * @param string $message
19
     */
20
    protected static function validRelayState(string $value, string $message = ''): void
21
    {
22
        parent::notWhitespaceOnly($value, $message); // Not protocol-defined, but makes zero sense
23
        try {
24
            /**
25
             * 3.4.3 RelayState
26
             *
27
             * The value MUST NOT exceed 80 bytes in length [..]
28
             */
29
            parent::maxLength(
30
                $value,
31
                C::MAX_RELAY_STATE_LENGTH,
32
                $message ?: '%s is not a SAML2.0-compliant RelayState',
33
            );
34
        } catch (AssertionFailedException $e) {
35
            throw new ProtocolViolationException($e->getMessage());
36
        }
37
    }
38
}
39