AbstractRealGroup::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 1
nop 8
dl 0
loc 25
rs 9.8333
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 SimpleSAML\XMLSchema\XML;
6
7
use SimpleSAML\XML\Assert\Assert;
8
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
9
use SimpleSAML\XMLSchema\Type\IDValue;
10
use SimpleSAML\XMLSchema\Type\NCNameValue;
11
use SimpleSAML\XMLSchema\Type\QNameValue;
12
use SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue;
13
use SimpleSAML\XMLSchema\Type\Schema\MinOccursValue;
14
use SimpleSAML\XMLSchema\XML\Constants\NS;
15
use SimpleSAML\XMLSchema\XML\Interface\ParticleInterface;
16
17
use function is_null;
18
19
/**
20
 * Abstract class representing the realGroup-type.
21
 *
22
 * @package simplesamlphp/xml-common
23
 */
24
abstract class AbstractRealGroup extends AbstractGroup
25
{
26
    /** The namespace-attribute for the xs:anyAttribute element */
27
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
28
29
30
    /**
31
     * Group constructor
32
     *
33
     * @param \SimpleSAML\XMLSchema\XML\Interface\ParticleInterface|null $particle
34
     * @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $name
35
     * @param \SimpleSAML\XMLSchema\Type\QNameValue|null $reference
36
     * @param \SimpleSAML\XMLSchema\Type\Schema\MinOccursValue|null $minOccurs
37
     * @param \SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue|null $maxOccurs
38
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
39
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
40
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
41
     */
42
    public function __construct(
43
        ?ParticleInterface $particle = null,
44
        ?NCNameValue $name = null,
45
        ?QNameValue $reference = null,
46
        ?MinOccursValue $minOccurs = null,
47
        ?MaxOccursValue $maxOccurs = null,
48
        ?Annotation $annotation = null,
49
        ?IDValue $id = null,
50
        array $namespacedAttributes = [],
51
    ) {
52
        Assert::nullOrIsInstanceOf(
53
            $particle,
54
            ParticleInterface::class,
55
            SchemaViolationException::class,
56
        );
57
58
        parent::__construct(
59
            $name,
60
            $reference,
61
            $minOccurs,
62
            $maxOccurs,
63
            is_null($particle) ? [] : [$particle],
64
            $annotation,
65
            $id,
66
            $namespacedAttributes,
67
        );
68
    }
69
}
70