AbstractRequestType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 17
c 2
b 0
f 0
dl 0
loc 76
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 4
A getRequest() 0 3 1
A toUnsignedXML() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML11\Type\SAMLDateTimeValue;
10
use SimpleSAML\SAML11\XML\saml\AssertionIDReference;
11
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12
use SimpleSAML\XMLSchema\Type\{IDValue, NonNegativeIntegerValue};
13
14
use function array_pop;
15
use function is_array;
16
17
/**
18
 * Base class for all SAML 1.1 requests.
19
 *
20
 * @package simplesamlphp/saml11
21
 */
22
abstract class AbstractRequestType extends AbstractRequestAbstractType
23
{
24
    /**
25
     * Initialize a request.
26
     *
27
     * @param (
28
     *   \SimpleSAML\SAML11\XML\samlp\AbstractQueryAbstractType|
29
     *   array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference>|
30
     *   array<\SimpleSAML\SAML11\XML\samlp\AssertionArtifact>
31
     * ) $request
32
     * @param \SimpleSAML\XMLSchema\Type\IDValue $id
33
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $majorVersion
34
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $minorVersion
35
     * @param \SimpleSAML\SAML11\Type\SAMLDateTimeValue $issueInstant
36
     * @param array<\SimpleSAML\SAML11\XML\samlp\RespondWith> $respondWith
37
     *
38
     * @throws \Exception
39
     */
40
    protected function __construct(
41
        protected AbstractQueryAbstractType|array $request,
42
        IDValue $id,
43
        NonNegativeIntegerValue $majorVersion,
44
        NonNegativeIntegerValue $minorVersion,
45
        SAMLDateTimeValue $issueInstant,
46
        array $respondWith = [],
47
    ) {
48
        if (is_array($request)) {
0 ignored issues
show
introduced by
The condition is_array($request) is always true.
Loading history...
49
            Assert::minCount($request, 1, SchemaViolationException::class);
50
51
            $req = array_pop($request);
52
            if ($req instanceof AssertionIDReference) {
53
                Assert::allIsInstanceOf($request, AssertionIDReference::class, SchemaViolationException::class);
54
            } elseif ($req instanceof AssertionArtifact) {
55
                Assert::allIsInstanceOf($request, AssertionArtifact::class, SchemaViolationException::class);
56
            } else {
57
                throw new SchemaViolationException();
58
            }
59
        }
60
61
        parent::__construct($id, $majorVersion, $minorVersion, $issueInstant, $respondWith);
62
    }
63
64
65
    /**
66
     * Retrieve the request inside this request.
67
     *
68
     * @return (
1 ignored issue
show
Documentation Bug introduced by
The doc comment ( at position 1 could not be parsed: the token is null at position 1.
Loading history...
69
     *   \SimpleSAML\SAML11\XML\samlp\AbstractQueryAbstractType|
70
     *   array<\SimpleSAML\SAML11\XML\saml\AssertionIDReference>|
71
     *   array<\SimpleSAML\SAML11\XML\samlp\AssertionArtifact>
72
     * )
73
     */
74
    public function getRequest(): AbstractQueryAbstractType|array
75
    {
76
        return $this->request;
77
    }
78
79
80
    /**
81
     * Convert this message to an unsigned XML document.
82
     * This method does not sign the resulting XML document.
83
     *
84
     * @return \DOMElement The root element of the DOM tree
85
     */
86
    protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
87
    {
88
        $e = parent::toUnsignedXML($parent);
89
90
        $requests = $this->getRequest();
91
        $requests = is_array($requests) ? $requests : [$requests];
92
93
        foreach ($requests as $request) {
94
            $request->toXML($e);
95
        }
96
97
        return $e;
98
    }
99
}
100