Subject   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
c 0
b 0
f 0
dl 0
loc 85
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 20 2
A __construct() 0 15 2
A getSubjectConfirmation() 0 3 1
A toXML() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\XML\IdentifierTrait;
10
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...
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
15
16
/**
17
 * Class representing SAML 2 Subject element.
18
 *
19
 * @package simplesamlphp/saml2
20
 */
21
final class Subject extends AbstractSamlElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\AbstractSamlElement 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...
22
{
23
    use IdentifierTrait;
24
    use SchemaValidatableElementTrait;
25
26
27
    /**
28
     * Initialize a Subject element.
29
     *
30
     * @param \SimpleSAML\SAML2\XML\saml\IdentifierInterface|null $identifier
31
     * @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmation[] $subjectConfirmation
32
     */
33
    public function __construct(
34
        ?IdentifierInterface $identifier,
35
        protected array $subjectConfirmation = [],
36
    ) {
37
        if (empty($subjectConfirmation)) {
38
            Assert::notNull(
39
                $identifier,
40
                'A <saml:Subject> not containing <saml:SubjectConfirmation> should provide exactly one of '
41
                    . '<saml:BaseID>, <saml:NameID> or <saml:EncryptedID>',
42
            );
43
        }
44
        Assert::maxCount($subjectConfirmation, C::UNBOUNDED_LIMIT);
45
        Assert::allIsInstanceOf($subjectConfirmation, SubjectConfirmation::class);
46
47
        $this->setIdentifier($identifier);
48
    }
49
50
51
    /**
52
     * Collect the value of the SubjectConfirmation-property
53
     *
54
     * @return \SimpleSAML\SAML2\XML\saml\SubjectConfirmation[]
55
     */
56
    public function getSubjectConfirmation(): array
57
    {
58
        return $this->subjectConfirmation;
59
    }
60
61
62
    /**
63
     * Convert XML into a Subject
64
     *
65
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
66
     *   if the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, 'Subject', InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, Subject::NS, InvalidDOMElementException::class);
72
73
        $identifier = self::getIdentifierFromXML($xml);
74
        $subjectConfirmation = SubjectConfirmation::getChildrenOfClass($xml);
75
76
        if (empty($subjectConfirmation)) {
77
            Assert::notNull(
78
                $identifier,
79
                'A <saml:Subject> not containing <saml:SubjectConfirmation> should provide' .
80
                ' exactly one of <saml:BaseID>, <saml:NameID> or <saml:EncryptedID>',
81
                TooManyElementsException::class,
82
            );
83
        }
84
85
        return new static(
86
            $identifier,
87
            $subjectConfirmation,
88
        );
89
    }
90
91
92
    /**
93
     * Convert this element to XML.
94
     */
95
    public function toXML(?DOMElement $parent = null): DOMElement
96
    {
97
        $e = $this->instantiateParentElement($parent);
98
99
        $this->getIdentifier()?->toXML($e);
0 ignored issues
show
Bug introduced by
The method toXML() does not exist on SimpleSAML\SAML2\XML\saml\IdentifierInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SimpleSAML\SAML2\XML\saml\BaseIdentifierInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

99
        $this->getIdentifier()?->/** @scrutinizer ignore-call */ toXML($e);
Loading history...
100
101
        foreach ($this->getSubjectConfirmation() as $sc) {
102
            $sc->toXML($e);
103
        }
104
105
        return $e;
106
    }
107
}
108