Completed
Push — master ( f72cfb...4ef12f )
by Tim
21s queued 18s
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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 4 1
A sanitizeValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\Type\Builtin;
6
7
use SimpleSAML\XML\Assert\Assert;
8
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
9
use SimpleSAML\XMLSchema\Type\Helper\AbstractAnySimpleType;
10
11
use function preg_replace;
12
13
/**
14
 * @package simplesaml/xml-common
15
 */
16
class Base64BinaryValue extends AbstractAnySimpleType
17
{
18
    /** @var string */
19
    public const SCHEMA_TYPE = 'base64Binary';
20
21
22
    /**
23
     * Sanitize the value.
24
     *
25
     * @param string $value  The unsanitized value
26
     * @return string
27
     */
28
    protected function sanitizeValue(string $value): string
29
    {
30
        return preg_replace('/\s/', '', $value);
31
    }
32
33
34
    /**
35
     * Validate the value.
36
     *
37
     * @param string $value
38
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
39
     * @return void
40
     */
41
    protected function validateValue(string $value): void
42
    {
43
        // Note: value must already be sanitized before validating
44
        Assert::validBase64Binary($this->sanitizeValue($value), SchemaViolationException::class);
45
    }
46
}
47