Transforms   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 2
b 0
f 0
dl 0
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmptyElement() 0 3 1
A __construct() 0 5 1
A getTransform() 0 3 1
A fromXML() 0 8 1
A toXML() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\Constants 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\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
12
use SimpleSAML\XMLSecurity\XML\ds\Transform;
13
14
/**
15
 * Class representing a xenc:Transforms element.
16
 *
17
 * @package simplesamlphp/xml-security
18
 */
19
final class Transforms extends AbstractXencElement
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\X...enc\AbstractXencElement 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...
20
{
21
    /**
22
     * Initialize a xenc:Transforms
23
     *
24
     * @param \SimpleSAML\XMLSecurity\XML\ds\Transform[] $transform
25
     */
26
    public function __construct(
27
        protected array $transform,
28
    ) {
29
        Assert::maxCount($transform, C::UNBOUNDED_LIMIT);
30
        Assert::allIsInstanceOf($transform, Transform::class, InvalidArgumentException::class);
31
    }
32
33
34
    /**
35
     * @return \SimpleSAML\XMLSecurity\XML\ds\Transform[]
36
     */
37
    public function getTransform(): array
38
    {
39
        return $this->transform;
40
    }
41
42
43
    /**
44
     * Test if an object, at the state it's in, would produce an empty XML-element
45
     */
46
    public function isEmptyElement(): bool
47
    {
48
        return empty($this->transform);
49
    }
50
51
52
    /**
53
     * Convert XML into a Transforms element
54
     *
55
     * @param \DOMElement $xml The XML element we should load
56
     *
57
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58
     *   If the qualified name of the supplied element is wrong
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, 'Transforms', InvalidDOMElementException::class);
63
        Assert::same($xml->namespaceURI, Transforms::NS, InvalidDOMElementException::class);
64
65
        $transform = Transform::getChildrenOfClass($xml);
66
67
        return new static($transform);
68
    }
69
70
71
    /**
72
     * Convert this Transforms element to XML.
73
     *
74
     * @param \DOMElement|null $parent The element we should append this Transforms element to.
75
     */
76
    public function toXML(?DOMElement $parent = null): DOMElement
77
    {
78
        $e = $this->instantiateParentElement($parent);
79
80
        foreach ($this->getTransform() as $t) {
81
            if (!$t->isEmptyElement()) {
82
                $t->toXML($e);
83
            }
84
        }
85
86
        return $e;
87
    }
88
}
89