Passed
Pull Request — master (#61)
by Tim
02:17
created

AbstractRealGroup::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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