Passed
Push — master ( 8413b2...00f101 )
by Tim
02:19
created

AbstractRealGroup::__construct()   A

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