Issues (81)

src/XML/ds/DigestMethod.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\ExtendableElementTrait;
10
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException};
12
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13
use SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum;
14
use SimpleSAML\XMLSecurity\Constants as C;
15
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
16
17
use function strval;
18
19
/**
20
 * Class representing a ds:DigestMethod element.
21
 *
22
 * @package simplesamlphp/xml-security
23
 */
24
final class DigestMethod extends AbstractDsElement implements SchemaValidatableElementInterface
25
{
26
    use ExtendableElementTrait;
27
    use SchemaValidatableElementTrait;
0 ignored issues
show
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\ds\DigestMethod: $message, $line
Loading history...
28
29
    /** The namespace-attribute for the xs:any element */
30
    public const XS_ANY_ELT_NAMESPACE = NamespaceEnum::Other;
31
32
    /**
33
     * Initialize a DigestMethod element.
34
     *
35
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $Algorithm
36
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $elements
0 ignored issues
show
The type SimpleSAML\XMLSecurity\XML\ds\list 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...
37
     */
38
    public function __construct(
39
        protected AnyURIValue $Algorithm,
40
        array $elements = [],
41
    ) {
42
        Assert::oneOf(
43
            $Algorithm->getValue(),
44
            array_keys(C::$DIGEST_ALGORITHMS),
45
            'Invalid digest method: %s',
46
            InvalidArgumentException::class,
47
        );
48
49
        $this->setElements($elements);
50
    }
51
52
53
    /**
54
     * Collect the value of the Algorithm-property
55
     *
56
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
57
     */
58
    public function getAlgorithm(): AnyURIValue
59
    {
60
        return $this->Algorithm;
61
    }
62
63
64
    /**
65
     * Convert XML into a DigestMethod
66
     *
67
     * @param \DOMElement $xml The XML element we should load
68
     * @return static
69
     *
70
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
71
     *   If the qualified name of the supplied element is wrong
72
     */
73
    public static function fromXML(DOMElement $xml): static
74
    {
75
        Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class);
76
        Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class);
77
78
        $Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class);
79
        $elements = self::getChildElementsFromXML($xml);
80
81
        return new static($Algorithm, $elements);
82
    }
83
84
85
    /**
86
     * Convert this DigestMethod element to XML.
87
     *
88
     * @param \DOMElement|null $parent The element we should append this DigestMethod element to.
89
     * @return \DOMElement
90
     */
91
    public function toXML(?DOMElement $parent = null): DOMElement
92
    {
93
        $e = $this->instantiateParentElement($parent);
94
        $e->setAttribute('Algorithm', strval($this->getAlgorithm()));
95
96
        foreach ($this->elements as $elt) {
97
            if (!$elt->isEmptyElement()) {
98
                $elt->toXML($e);
99
            }
100
        }
101
102
        return $e;
103
    }
104
}
105