Passed
Push — master ( 4ef12f...97a942 )
by Tim
04:38 queued 02:20
created

LangValue::validateValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\Type;
6
7
use SimpleSAML\XML\Attribute;
8
use SimpleSAML\XML\Constants as C;
9
use SimpleSAML\XMLSchema\Type\Builtin\LanguageValue;
10
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;
11
12
/**
13
 * @package simplesaml/xml-common
14
 */
15
class LangValue extends LanguageValue implements AttributeTypeInterface
16
{
17
    /** @var string */
18
    public const SCHEMA_TYPE = 'xs:language';
19
20
21
    /**
22
     * Validate the value.
23
     *
24
     * @param string $value
25
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
26
     * @return void
27
     */
28
    protected function validateValue(string $value): void
29
    {
30
        $sanitized = $this->sanitizeValue($value);
31
32
        if ($sanitized !== '') {
33
            parent::validateValue($sanitized);
34
        }
35
    }
36
37
38
    /**
39
     * Convert this value to an attribute
40
     *
41
     * @return \SimpleSAML\XML\Attribute
42
     */
43
    public function toAttribute(): Attribute
44
    {
45
        return new Attribute(C::NS_XML, 'xml', 'lang', $this);
46
    }
47
}
48