Passed
Pull Request — master (#6)
by Tim
02:09
created

StringTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validString() 0 15 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
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * @package simplesamlphp/saml11
13
 */
14
trait StringTrait
15
{
16
    /**
17
     * @param string $value
18
     * @param string $message
19
     */
20
    protected static function validString(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