Passed
Pull Request — master (#226)
by Jaime Pérez
02:37
created

AbstractSubjectQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 8
dl 0
loc 13
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\XML\samlp;
6
7
use DOMElement;
8
use SAML2\XML\saml\Issuer;
9
use SAML2\XML\saml\Subject;
10
use Webmozart\Assert\Assert;
11
12
/**
13
 * Base class for SAML 2 subject query messages.
14
 *
15
 * This base class can be used for various requests which ask for
16
 * information about a particular subject.
17
 *
18
 * Note that this class currently only handles the simple case - where the
19
 * subject doesn't contain any sort of subject confirmation requirements.
20
 *
21
 * @package SimpleSAMLphp
22
 */
23
abstract class AbstractSubjectQuery extends AbstractRequest
24
{
25
    /** @var \SAML2\XML\saml\Subject */
26
    protected $subject;
27
28
29
30
    /**
31
     * Constructor for SAML 2 response messages.
32
     *
33
     * @param \SAML2\XML\saml\Subject $subject
34
     * @param \SAML2\XML\saml\Issuer $issuer
35
     * @param string $id
36
     * @param string $version
37
     * @param int $issueInstant
38
     * @param string|null $destination
39
     * @param string|null $consent
40
     * @param \SAML2\XML\samlp\Extensions $extensions
41
     */
42
    protected function __construct(
43
        Subject $subject,
44
        ?Issuer $issuer = null,
45
        ?string $id = null,
46
        ?string $version = '2.0',
47
        ?int $issueInstant = null,
48
        ?string $destination = null,
49
        ?string $consent = null,
50
        ?Extensions $extensions = null
51
    ) {
52
        parent::__construct($issuer, $id, $version, $issueInstant, $destination, $consent, $extensions);
53
54
        $this->setSubject($subject);
55
    }
56
57
58
    /**
59
     * Collect the value of the subject
60
     *
61
     * @return \SAML2\XML\saml\Subject
62
     */
63
    public function getSubject(): Subject
64
    {
65
        return $this->subject;
66
    }
67
68
69
    /**
70
     * Set the value of the subject-property
71
     * @param \SAML2\XML\saml\Subject $subject
72
     *
73
     * @return void
74
     */
75
    private function setSubject(Subject $subject): void
76
    {
77
        $this->subject = $subject;
78
    }
79
80
81
    /**
82
     * Convert subject query message to an XML element.
83
     *
84
     * @return \DOMElement This subject query.
85
     *
86
     * @throws \InvalidArgumentException if assertions are false
87
     */
88
    public function toXML(?DOMElement $parent = null): DOMElement
89
    {
90
        Assert::null($parent);
91
        Assert::notEmpty($this->subject, 'Cannot convert SubjectQuery to XML without a Subject set.');
92
93
        $parent = parent::toXML();
94
95
        $this->subject->toXML($parent);
96
97
        return $parent;
98
    }
99
}
100