Passed
Pull Request — master (#374)
by Tim
11:54 queued 09:21
created

SAMLStringTrait::validSAMLString()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assert;
6
7
use SimpleSAML\Assert\AssertionFailedException;
8
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * @package simplesamlphp/saml2
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
        try {
24
            /**
25
             * 1.3.1 String Values
26
             *
27
             * Unless otherwise noted in this specification or particular profiles, all strings in
28
             * SAML messages MUST consist of at least one non-whitespace character
29
             */
30
            parent::notWhitespaceOnly($value, $message ?: '%s is not a SAML2.0-compliant string');
31
        } catch (AssertionFailedException $e) {
32
            throw new ProtocolViolationException($e->getMessage());
33
        }
34
    }
35
}
36