Passed
Pull Request — main (#39)
by Tom
02:16
created

Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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