Passed
Pull Request — main (#128)
by Tom
04:00 queued 01:14
created

Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 8
dl 0
loc 14
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;
0 ignored issues
show
Bug introduced by
The trait ApiSkeletons\Doctrine\Gr...tribute\ExcludeCriteria requires the property $exccludeCriteria which is not provided by ApiSkeletons\Doctrine\GraphQL\Attribute\Entity.
Loading history...
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
    /** @var string|null Documentation for the entity within GraphQL */
21
    private string|null $description = null;
22
23
    /**
24
     * @var mixed[] An array of filters as
25
     * [
26
     *   'condition' => FilterComposite::CONDITION_AND,
27
     *   'filter' => 'Filter\ClassName',
28
     * ]
29
     */
30
    private array $filters = [];
31
32
    /**
33
     * @param mixed[]  $filters
34
     * @param string[] $excludeCriteria
35
     * @param string[] $includeCriteria
36
     */
37
    public function __construct(
38
        string $group = 'default',
39
        bool $byValue = true,
40
        string|null $description = null,
41
        private string|null $typeName = null,
42
        array $filters = [],
43
        private string|null $namingStrategy = null,
44
        private array $excludeCriteria = [],
45
        private array $includeCriteria = [],
46
    ) {
47
        $this->group       = $group;
48
        $this->byValue     = $byValue;
49
        $this->description = $description;
50
        $this->filters     = $filters;
51
    }
52
53
    public function getGroup(): string|null
54
    {
55
        return $this->group;
56
    }
57
58
    public function getByValue(): bool
59
    {
60
        return $this->byValue;
61
    }
62
63
    public function getDescription(): string|null
64
    {
65
        return $this->description;
66
    }
67
68
    public function getTypeName(): string|null
69
    {
70
        return $this->typeName;
71
    }
72
73
    /** @return mixed[] */
74
    public function getFilters(): array
75
    {
76
        return $this->filters;
77
    }
78
79
    public function getNamingStrategy(): string|null
80
    {
81
        return $this->namingStrategy;
82
    }
83
}
84