AbstractRequestSecurityTokenCollectionType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 63
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 9 2
A getRequestSecurityToken() 0 3 1
A __construct() 0 8 1
A fromXML() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200512;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
13
/**
14
 * A RequestSecurityTokenCollectionType element
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractRequestSecurityTokenCollectionType extends AbstractWstElement
19
{
20
    /**
21
     * @param array<\SimpleSAML\WSSecurity\XML\wst_200512\RequestSecurityToken> $requestSecurityToken
22
     */
23
    final public function __construct(
24
        protected array $requestSecurityToken,
25
    ) {
26
        Assert::minCount($requestSecurityToken, 2, MissingElementException::class);
0 ignored issues
show
Bug introduced by
The method minCount() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        Assert::/** @scrutinizer ignore-call */ 
27
                minCount($requestSecurityToken, 2, MissingElementException::class);
Loading history...
27
        Assert::allIsInstanceOf(
0 ignored issues
show
Bug introduced by
The method allIsInstanceOf() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        Assert::/** @scrutinizer ignore-call */ 
28
                allIsInstanceOf(
Loading history...
28
            $requestSecurityToken,
29
            RequestSecurityToken::class,
30
            SchemaViolationException::class,
31
        );
32
    }
33
34
35
    /**
36
     * Get the requestSecurityToken property.
37
     *
38
     * @return \SimpleSAML\WSSecurity\XML\wst_200512\RequestSecurityToken[]
39
     */
40
    public function getRequestSecurityToken(): array
41
    {
42
        return $this->requestSecurityToken;
43
    }
44
45
46
    /**
47
     * Convert XML into a class instance
48
     *
49
     * @param \DOMElement $xml The XML element we should load
50
     * @return static
51
     *
52
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
53
     *   If the qualified name of the supplied element is wrong
54
     */
55
    public static function fromXML(DOMElement $xml): static
56
    {
57
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
0 ignored issues
show
Bug introduced by
The method same() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        Assert::/** @scrutinizer ignore-call */ 
58
                same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Loading history...
58
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
59
60
        return new static(
61
            RequestSecurityToken::getChildrenOfClass($xml),
62
        );
63
    }
64
65
66
    /**
67
     * Convert this element to XML.
68
     *
69
     * @param \DOMElement|null $parent The element we should append this element to.
70
     * @return \DOMElement
71
     */
72
    public function toXML(?DOMElement $parent = null): DOMElement
73
    {
74
        $e = $this->instantiateParentElement($parent);
75
76
        foreach ($this->getRequestSecurityToken() as $r) {
77
            $r->toXML($e);
78
        }
79
80
        return $e;
81
    }
82
}
83