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

LangValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toAttribute() 0 3 1
A validateValue() 0 6 2
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