Passed
Pull Request — main (#136)
by Tom
06:29 queued 03:33
created

Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 9
dl 0
loc 16
rs 10

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 ApiSkeletons\Doctrine\GraphQL\Attribute;
6
7
use Attribute;
8
9
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
10
final class Entity
11
{
12
    use ExcludeCriteria;
13
14
    /** @var string The GraphQL group */
15
    private string $group;
16
17
    /** @var bool Extract by value: true, or by reference: false */
18
    private bool $byValue;
19
20
    /**
21
     * When this value is 0 the limit falls back to the global config limit
22
     *
23
     * @var int A hard limit for all queries on this entity
24
     */
25
    private int $limit;
26
27
    /** @var string|null Documentation for the entity within GraphQL */
28
    private string|null $description = null;
29
30
    /**
31
     * @var mixed[] An array of filters as
32
     * [
33
     *   'condition' => FilterComposite::CONDITION_AND,
34
     *   'filter' => 'Filter\ClassName',
35
     * ]
36
     */
37
    private array $filters = [];
38
39
    /**
40
     * @param mixed[]  $filters
41
     * @param string[] $excludeCriteria
42
     * @param string[] $includeCriteria
43
     */
44
    public function __construct(
45
        string $group = 'default',
46
        bool $byValue = true,
47
        int $limit = 0,
48
        string|null $description = null,
49
        private string|null $typeName = null,
50
        array $filters = [],
51
        private string|null $namingStrategy = null,
52
        private array $excludeCriteria = [],
53
        private array $includeCriteria = [],
54
    ) {
55
        $this->group       = $group;
56
        $this->byValue     = $byValue;
57
        $this->limit       = $limit;
58
        $this->description = $description;
59
        $this->filters     = $filters;
60
    }
61
62
    public function getGroup(): string|null
63
    {
64
        return $this->group;
65
    }
66
67
    public function getByValue(): bool
68
    {
69
        return $this->byValue;
70
    }
71
72
    public function getLimit(): int
73
    {
74
        return $this->limit;
75
    }
76
77
    public function getDescription(): string|null
78
    {
79
        return $this->description;
80
    }
81
82
    public function getTypeName(): string|null
83
    {
84
        return $this->typeName;
85
    }
86
87
    /** @return mixed[] */
88
    public function getFilters(): array
89
    {
90
        return $this->filters;
91
    }
92
93
    public function getNamingStrategy(): string|null
94
    {
95
        return $this->namingStrategy;
96
    }
97
}
98