Passed
Pull Request — master (#19)
by Tim
02:42
created

AbstractFreshnessType::validateContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException};
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\Exception\SchemaViolationException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type SimpleSAML\XML\Exception...alidDOMElementException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SimpleSAML\XML\{ExtendableAttributesTrait, TypedTextContentTrait};
11
use SimpleSAML\XML\Type\{BooleanValue, UnsignedIntValue};
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\Type\BooleanValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type SimpleSAML\XML\Type\UnsignedIntValue was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use SimpleSAML\XML\XsNamespace as NS;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\XsNamespace was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
use function var_export;
15
16
/**
17
 * Class defining the FreshnessType element
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractFreshnessType extends AbstractFedElement
22
{
23
    use TypedTextContentTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...d\AbstractFreshnessType: $localName, $namespaceURI
Loading history...
24
    use ExtendableAttributesTrait;
25
26
    /** @var string */
27
    public const TEXTCONTENT_TYPE = UnsignedIntValue::class;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * AbstractFreshnessType constructor
35
     *
36
     * @param \SimpleSAML\XML\Type\UnsignedIntValue $content
37
     * @param \SimpleSAML\XML\Type\BooleanValue|null $AllowCache
38
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
39
     */
40
    final public function __construct(
41
        UnsignedIntValue $content,
42
        protected ?BooleanValue $AllowCache = null,
43
        array $namespacedAttributes = [],
44
    ) {
45
        $this->setContent($content);
46
        $this->setAttributesNS($namespacedAttributes);
47
    }
48
49
50
    /**
51
     * @return \SimpleSAML\XML\Type\BooleanValue|null
52
     */
53
    public function getAllowCache(): ?BooleanValue
54
    {
55
        return $this->AllowCache;
56
    }
57
58
59
    /**
60
     * Create an instance of this object from its XML representation.
61
     *
62
     * @param \DOMElement $xml
63
     * @return static
64
     *
65
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
66
     *   if the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
72
73
        return new static(
74
            UnsignedIntValue::fromString($xml->textContent),
75
            self::getOptionalAttribute($xml, 'AllowCache', BooleanValue::class, null),
76
            self::getAttributesNSFromXML($xml),
77
        );
78
    }
79
80
81
    /**
82
     * Add this IssuerNameType to an XML element.
83
     *
84
     * @param \DOMElement|null $parent The element we should append this issuer name to.
85
     * @return \DOMElement
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = parent::instantiateParentElement($parent);
90
        $e->textContent = $this->getContent()->getValue();
91
92
        if ($this->getAllowCache() !== null) {
93
            $e->setAttribute('AllowCache', var_export($this->getAllowCache()->toBoolean(), true));
94
        }
95
96
        foreach ($this->getAttributesNS() as $attr) {
97
            $attr->toXML($e);
98
        }
99
100
        return $e;
101
    }
102
}
103