Passed
Branch feature/php8.3 (4d3b0a)
by Tim
17:15
created

Base64BinaryValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\Type;
6
7
use SimpleSAML\XML\Assert\Assert;
8
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
9
use SimpleSAML\XMLSchema\Type\Interface\AbstractAnySimpleType;
10
11
use function preg_replace;
12
13
/**
14
 * @package simplesaml/xml-common
15
 */
16
class Base64BinaryValue extends AbstractAnySimpleType
17
{
18
    public const string SCHEMA_TYPE = 'base64Binary';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 18 at column 24
Loading history...
19
20
21
    /**
22
     * Sanitize the value.
23
     *
24
     * @param string $value  The unsanitized value
25
     */
26
    protected function sanitizeValue(string $value): string
27
    {
28
        return preg_replace('/\s/', '', $value);
29
    }
30
31
32
    /**
33
     * Validate the value.
34
     *
35
     * @param string $value
36
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
37
     */
38
    protected function validateValue(string $value): void
39
    {
40
        // Note: value must already be sanitized before validating
41
        Assert::validBase64Binary($this->sanitizeValue($value), SchemaViolationException::class);
42
    }
43
}
44