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