| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class MustUnderstandValue extends BooleanValue implements AttributeTypeInterface |
||
| 20 | { |
||
| 21 | public const string SCHEMA_TYPE = 'boolean'; |
||
|
|
|||
| 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 |