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

SAMLStringTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 19
rs 10
c 1
b 0
f 0
wmc 3

1 Method

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