Passed
Push — master ( f21217...7f49bc )
by Tim
15:21 queued 13:12
created

AuthzDecisionQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
10
//use SimpleSAML\SAML2\Exception\ProtocolViolationException;
11
use SimpleSAML\XML\Exception\InvalidDOMElementException;
12
//use SimpleSAML\XML\Exception\MissingElementException;
13
//use SimpleSAML\XML\Exception\SchemaViolationException;
14
//use SimpleSAML\XML\Exception\TooManyElementsException;
15
//use SimpleSAML\XML\Utils as XMLUtils;
16
17
//use function array_pop;
18
//use function gmdate;
19
20
/**
21
 * Class representing a SAML2 AuthzDecisionQuery
22
 *
23
 * @package simplesamlphp/saml2
24
 */
25
final class AuthzDecisionQuery extends AbstractSubjectQuery
26
{
27
    /**
28
     * Initialize an AuthzDecisionQuery.
29
     *
30
     * @param string $resource
31
     * @param string $decision
32
     * @param \SimpleSAML\SAML2\XML\saml\Action[] $action
33
     * @param \SimpleSAML\SAML2\XML\saml\Evidence|null
34
     */
35
    public function __construct(
36
        protected string $resource,
37
        protected string $decision,
38
        protected array $action,
39
        protected ?Evidence $evidence = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\Evidence 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...
40
    ) {
41
        Assert::validURI($resource);
42
        Assert::oneOf($decision, C::AUTHZ_DECISIONS, ProtocolViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\sam...tocolViolationException 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...
43
        Assert::allIsInstanceOf($action, Action::class, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\sam...chemaViolationException 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...
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\Action 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...
44
    }
45
46
47
    /**
48
     * Collect the value of the resource-property
49
     *
50
     * @return string
51
     */
52
    public function getResource(): string
53
    {
54
        return $this->resource;
55
    }
56
57
58
    /**
59
     * Collect the value of the decision-property
60
     *
61
     * @return string
62
     */
63
    public function getDecision(): string
64
    {
65
        return $this->decision;
66
    }
67
68
69
    /**
70
     * Collect the value of the action-property
71
     *
72
     * @return array
73
     */
74
    public function getAction(): array
75
    {
76
        return $this->action;
77
    }
78
79
80
    /**
81
     * Collect the value of the evidence-property
82
     *
83
     * @return \SimpleSAML\SAML2\XML\saml\Evidence|null
84
     */
85
    public function getEvidence(): ?Evidence
86
    {
87
        return $this->evidence;
88
    }
89
90
91
    /**
92
     * Convert XML into an AuthzDecisionQuery
93
     *
94
     * @param \DOMElement $xml The XML element we should load
95
     *
96
     * @return static
97
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
98
     *   if the qualified name of the supplied element is wrong
99
     * @throws \SimpleSAML\XML\Exception\MissingElementException
100
     *   if one of the mandatory child-elements is missing
101
     * @throws \Exception if the authentication instant is not a valid timestamp.
102
     */
103
    public static function fromXML(DOMElement $xml): static
104
    {
105
        Assert::same($xml->localName, 'AuthzDecisionQuery', InvalidDOMElementException::class);
106
        Assert::same($xml->namespaceURI, AuthzDecisionQuery::NS, InvalidDOMElementException::class);
107
108
        $action = Action::getChildrenOfClass($xml);
109
        Assert::minCount(
110
            $action,
111
            1,
112
            'Missing <saml:Action> in <saml:AuthzDecisionQuery>',
113
            MissingElementException::class,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\MissingElementException 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...
114
        );
115
116
        $evidence = Evidence::getChildrenOfClass($xml);
117
        Assert::maxCount(
118
            $evidence,
119
            1,
120
            'Too many <saml:Evidence> in <saml:AuthzDecisionQuery>',
121
            TooManyElementsException::class,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\sam...ooManyElementsException 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...
122
        );
123
124
        return new static(
125
            self::getAttribute($xml, 'Resource'),
0 ignored issues
show
Bug introduced by
It seems like self::getAttribute($xml, 'Resource') can also be of type null; however, parameter $resource of SimpleSAML\SAML2\XML\sam...ionQuery::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

125
            /** @scrutinizer ignore-type */ self::getAttribute($xml, 'Resource'),
Loading history...
126
            self::getAttribute($xml, 'Decision'),
0 ignored issues
show
Bug introduced by
It seems like self::getAttribute($xml, 'Decision') can also be of type null; however, parameter $decision of SimpleSAML\SAML2\XML\sam...ionQuery::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

126
            /** @scrutinizer ignore-type */ self::getAttribute($xml, 'Decision'),
Loading history...
127
            $action,
128
            array_pop($evidence),
129
        );
130
    }
131
132
133
    /**
134
     * Convert this AuthzDecisionQuery to XML.
135
     *
136
     * @param \DOMElement|null $parent The element we should append this AuthzDecisionQuery to.
137
     * @return \DOMElement
138
     */
139
    public function toXML(DOMElement $parent = null): DOMElement
140
    {
141
        $e = $this->instantiateParentElement($parent);
142
143
        $e->setAttribute('Resource', $this->getResource());
144
        $e->setAttribute('Decision', $this->getDecision());
145
146
        foreach ($this->getAction() as $action) {
147
            $action->toXML($e);
148
        }
149
150
        if ($this->getEvidence() !== null && !$this->getEvidence()->isEmptyElement()) {
151
            $this->getEvidence()->toXML($e);
152
        }
153
154
        return $e;
155
    }
156
}
157