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

Config::setExcludeCriteria()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\ORM\GraphQL;
6
7
use ApiSkeletons\Doctrine\ORM\GraphQL\Filter\Filters;
8
9
/**
10
 * This class is used for setting parameters when
11
 * creating the driver
12
 */
13
class Config
14
{
15
    /**
16
     * @var string The GraphQL group. This allows multiple GraphQL
17
     *             configurations within the same application or
18
     *             even within the same group of entities and Object Manager.
19
     */
20
    protected string $group = 'default';
21
22
    /**
23
     * @var string|null The group is usually suffixed to GraphQL type names.
24
     *                  You may specify a different string for the group suffix
25
     *                  or you my supply an empty string to exclude the suffix.
26
     *                  Be warned, using the same groupSuffix with two different
27
     *                  groups can cause collisions.
28
     */
29
    protected string|null $groupSuffix = null;
30
31
    /**
32
     * @var bool When set to true hydrator results will be cached for the
33
     *           duration of the request thereby saving multiple extracts for
34
     *           the same entity.
35
     */
36
    protected bool $useHydratorCache = false;
37
38
    /** @var int A hard limit for fetching any collection within the schema */
39
    protected int $limit = 1000;
40
41
    /**
42
     * @var bool When set to true all fields and all associations will be
43
     *           enabled.  This is best used as a development setting when
44
     *           the entities are subject to change.
45
     */
46
    protected bool $globalEnable = false;
47
48
    /** @var string[] An array of field names to ignore when using globalEnable. */
49
    protected array $globalIgnore = [];
50
51
    /**
52
     * @var bool|null When set to true, all entities will be extracted by value
53
     *                across all hydrators in the driver.  When set to false,
54
     *                all hydrators will extract by reference.  This overrides
55
     *                per-entity attribute configuration.
56
     */
57
    protected bool|null $globalByValue = null;
58
59
    /**
60
     * @var string|null When set, the entityPrefix will be removed from each
61
     *                  type name.  This simplifies type names and makes reading
62
     *                  the GraphQL documentation easier.
63
     */
64
    protected string|null $entityPrefix = null;
65
66
    /**
67
     * @var bool|null When set to true entity fields will be
68
     *                sorted alphabetically
69
     */
70
    protected bool|null $sortFields = null;
71
72
    /**
73
     * @var Filters[] An array of filters to exclude from
74
     *                available filters for all fields and
75
     *                associations in every entity
76
     */
77
    protected array $excludeFilters = [];
78
79
    /** @param mixed[] $config */
80
    public function __construct(array $config = [])
81
    {
82
        /**
83
         * Dynamic setters will fail for invalid settings and allow for
84
         * validation of field types through setters
85
         */
86
        foreach ($config as $setting => $value) {
87
            $setter = 'set' . $setting;
88
            $this->$setter($value);
89
        }
90
    }
91
92
    protected function setGroup(string $group): self
93
    {
94
        $this->group = $group;
95
96
        return $this;
97
    }
98
99
    public function getGroup(): string
100
    {
101
        return $this->group;
102
    }
103
104
    protected function setGroupSuffix(string|null $groupSuffix): self
105
    {
106
        $this->groupSuffix = $groupSuffix;
107
108
        return $this;
109
    }
110
111
    public function getGroupSuffix(): string|null
112
    {
113
        return $this->groupSuffix;
114
    }
115
116
    protected function setUseHydratorCache(bool $useHydratorCache): self
117
    {
118
        $this->useHydratorCache = $useHydratorCache;
119
120
        return $this;
121
    }
122
123
    public function getUseHydratorCache(): bool
124
    {
125
        return $this->useHydratorCache;
126
    }
127
128
    protected function setLimit(int $limit): self
129
    {
130
        $this->limit = $limit;
131
132
        return $this;
133
    }
134
135
    public function getLimit(): int
136
    {
137
        return $this->limit;
138
    }
139
140
    protected function setGlobalEnable(bool $globalEnable): self
141
    {
142
        $this->globalEnable = $globalEnable;
143
144
        return $this;
145
    }
146
147
    public function getGlobalEnable(): bool
148
    {
149
        return $this->globalEnable;
150
    }
151
152
    /** @param string[] $globalIgnore */
153
    protected function setGlobalIgnore(array $globalIgnore): self
154
    {
155
        $this->globalIgnore = $globalIgnore;
156
157
        return $this;
158
    }
159
160
    /** @return string[] */
161
    public function getGlobalIgnore(): array
162
    {
163
        return $this->globalIgnore;
164
    }
165
166
    protected function setGlobalByValue(bool|null $globalByValue): self
167
    {
168
        $this->globalByValue = $globalByValue;
169
170
        return $this;
171
    }
172
173
    public function getGlobalByValue(): bool|null
174
    {
175
        return $this->globalByValue;
176
    }
177
178
    protected function setEntityPrefix(string|null $entityPrefix): self
179
    {
180
        $this->entityPrefix = $entityPrefix;
181
182
        return $this;
183
    }
184
185
    public function getEntityPrefix(): string|null
186
    {
187
        return $this->entityPrefix;
188
    }
189
190
    public function setSortFields(bool|null $sortFields): self
191
    {
192
        $this->sortFields = $sortFields;
193
194
        return $this;
195
    }
196
197
    public function getSortFields(): bool|null
198
    {
199
        return $this->sortFields;
200
    }
201
202
    /** @param Filters[] $excludeFilters */
203
    public function setExcludeFilters(array $excludeFilters): self
204
    {
205
        $this->excludeFilters = $excludeFilters;
206
207
        return $this;
208
    }
209
210
    /** @return Filters[] */
211
    public function getExcludeFilters(): array
212
    {
213
        return $this->excludeFilters;
214
    }
215
}
216