Passed
Push — master ( 9d958a...532318 )
by Tim
02:50
created

MustUnderstandValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 6
c 0
b 0
f 0
dl 0
loc 49
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP11\Type;
6
7
use SimpleSAML\SOAP11\Assert\Assert;
8
use SimpleSAML\SOAP11\Constants as C;
9
use SimpleSAML\XML\Attribute;
10
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
11
use SimpleSAML\XMLSchema\Type\BooleanValue;
12
use SimpleSAML\XMLSchema\Type\Interface\AttributeTypeInterface;
13
14
use function boolval;
15
16
/**
17
 * @package simplesaml/xml-soap
18
 */
19
class MustUnderstandValue extends BooleanValue implements AttributeTypeInterface
20
{
21
    public const string SCHEMA_TYPE = 'boolean';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 21 at column 24
Loading history...
22
23
24
    /**
25
     * Validate the value.
26
     *
27
     * @param string $value
28
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
29
     */
30
    protected function validateValue(string $value): void
31
    {
32
        // Note: value must already be sanitized before validating
33
        Assert::validMustUnderstand($this->sanitizeValue($value), SchemaViolationException::class);
34
    }
35
36
37
    /**
38
     */
39
    public static function fromBoolean(bool $value): static
40
    {
41
        return new static(
42
            $value === true ? '1' : '0',
43
        );
44
    }
45
46
47
    /**
48
     */
49
    public function toBoolean(): bool
50
    {
51
        return boolval($this->getValue());
52
    }
53
54
55
    /**
56
     * Convert this value to an attribute
57
     *
58
     * @return \SimpleSAML\XML\Attribute
59
     */
60
    public function toAttribute(): Attribute
61
    {
62
        return new Attribute(C::NS_SOAP_ENV, 'SOAP-ENV', 'mustUnderstand', $this);
63
    }
64
}
65