AbstractNarrowMaxMin::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 15
dl 0
loc 36
rs 9.6666
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\BooleanValue;
10
use SimpleSAML\XMLSchema\Type\IDValue;
11
use SimpleSAML\XMLSchema\Type\NCNameValue;
12
use SimpleSAML\XMLSchema\Type\QNameValue;
13
use SimpleSAML\XMLSchema\Type\Schema\BlockSetValue;
14
use SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue;
15
use SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue;
16
use SimpleSAML\XMLSchema\Type\Schema\MinOccursValue;
17
use SimpleSAML\XMLSchema\Type\StringValue;
18
19
use function strval;
20
21
/**
22
 * Abstract class representing the narrowMaxMin-type.
23
 *
24
 * @package simplesamlphp/xml-common
25
 */
26
abstract class AbstractNarrowMaxMin extends AbstractLocalElement
27
{
28
    /**
29
     * Element constructor
30
     *
31
     * @param \SimpleSAML\XMLSchema\Type\NCNameValue|null $name
32
     * @param \SimpleSAML\XMLSchema\Type\QNameValue|null $reference
33
     * @param \SimpleSAML\XMLSchema\XML\LocalSimpleType|\SimpleSAML\XMLSchema\XML\LocalComplexType|null $localType
34
     * @param array<\SimpleSAML\XMLSchema\XML\Interface\IdentityConstraintInterface> $identityConstraint
35
     * @param \SimpleSAML\XMLSchema\Type\QNameValue|null $type
36
     * @param \SimpleSAML\XMLSchema\Type\Schema\MinOccursValue|null $minOccurs
37
     * @param \SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue|null $maxOccurs
38
     * @param \SimpleSAML\XMLSchema\Type\StringValue|null $default
39
     * @param \SimpleSAML\XMLSchema\Type\StringValue|null $fixed
40
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue|null $nillable
41
     * @param \SimpleSAML\XMLSchema\Type\Schema\BlockSetValue|null $block
42
     * @param \SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue|null $form
43
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
44
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
45
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
46
     */
47
    public function __construct(
48
        ?NCNameValue $name = null,
49
        ?QNameValue $reference = null,
50
        LocalSimpleType|LocalComplexType|null $localType = null,
51
        array $identityConstraint = [],
52
        ?QNameValue $type = null,
53
        ?MinOccursValue $minOccurs = null,
54
        ?MaxOccursValue $maxOccurs = null,
55
        ?StringValue $default = null,
56
        ?StringValue $fixed = null,
57
        ?BooleanValue $nillable = null,
58
        ?BlockSetValue $block = null,
59
        ?FormChoiceValue $form = null,
60
        ?Annotation $annotation = null,
61
        ?IDValue $id = null,
62
        array $namespacedAttributes = [],
63
    ) {
64
        Assert::oneOf(strval($minOccurs), ['0', '1'], SchemaViolationException::class);
65
        Assert::oneOf(strval($maxOccurs), ['0', '1'], SchemaViolationException::class);
66
67
        parent::__construct(
68
            name: $name,
69
            reference: $reference,
70
            localType: $localType,
71
            identityConstraint: $identityConstraint,
72
            type: $type,
73
            minOccurs: $minOccurs,
74
            maxOccurs: $maxOccurs,
75
            default: $default,
76
            fixed: $fixed,
77
            nillable: $nillable,
78
            block: $block,
79
            form: $form,
80
            annotation: $annotation,
81
            id: $id,
82
            namespacedAttributes: $namespacedAttributes,
83
        );
84
    }
85
}
86