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

SAMLStringTrait::validSAMLString()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
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
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
10
11
/**
12
 * @package simplesamlphp/saml11
13
 */
14
trait SAMLStringTrait
15
{
16
    /**
17
     * @param string $value
18
     * @param string $message
19
     */
20
    protected static function validSAMLString(string $value, string $message = ''): void
21
    {
22
        parent::validString($value, $message, SchemaViolationException::class);
23
24
        try {
25
            /**
26
             * 1.2.1 String and URI Values
27
             *
28
             * All strings in SAML messages MUST consist of at least one non-whitespace character
29
             * (whitespace is defined in the XML Recommendation [XML] §2.3).
30
             * Empty and whitespace-only values are disallowed.
31
             */
32
            static::notWhitespaceOnly($value, $message ?: '%s is not a SAML1.1-compliant string');
33
        } catch (AssertionFailedException $e) {
34
            throw new ProtocolViolationException($e->getMessage());
35
        }
36
    }
37
}
38