• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wol-soft / php-json-schema-model-generator / 24569325082

17 Apr 2026 02:06PM UTC coverage: 98.486% (-0.2%) from 98.654%
24569325082

Pull #125

github

wol-soft
additional test cases
Pull Request #125: attributes

1812 of 1837 new or added lines in 80 files covered. (98.64%)

1 existing line in 1 file now uncovered.

4554 of 4624 relevant lines covered (98.49%)

610.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.23
/src/Model/GeneratorConfiguration.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model;
6

7
use Exception;
8
use PHPModelGenerator\Draft\AutoDetectionDraft;
9
use PHPModelGenerator\Draft\DraftFactoryInterface;
10
use PHPModelGenerator\Draft\DraftInterface;
11
use PHPModelGenerator\Exception\ErrorRegistryException;
12
use PHPModelGenerator\Exception\InvalidFilterException;
13
use PHPModelGenerator\Filter\FilterInterface;
14
use PHPModelGenerator\Filter\TransformingFilterInterface;
15
use PHPModelGenerator\Format\FormatValidatorInterface;
16
use PHPModelGenerator\Model\Attributes\PhpAttribute;
17
use PHPModelGenerator\PropertyProcessor\Filter\DateTimeFilter;
18
use PHPModelGenerator\PropertyProcessor\Filter\NotEmptyFilter;
19
use PHPModelGenerator\PropertyProcessor\Filter\TrimFilter;
20
use PHPModelGenerator\Utils\ClassNameGenerator;
21
use PHPModelGenerator\Utils\ClassNameGeneratorInterface;
22

23
/**
24
 * Class GeneratorConfiguration
25
 *
26
 * @package PHPModelGenerator\Model
27
 */
28
class GeneratorConfiguration
29
{
30
    /** @var string */
31
    protected $namespacePrefix = '';
32
    /** @var bool */
33
    protected $immutable = true;
34
    /** @var bool */
35
    protected $allowImplicitNull = false;
36
    /** @var bool */
37
    protected $defaultArraysToEmptyArray = false;
38
    /** @var bool */
39
    protected $denyAdditionalProperties = false;
40
    /** @var bool */
41
    protected $outputEnabled = true;
42
    /** @var bool */
43
    protected $collectErrors = true;
44
    /** @var string */
45
    protected $errorRegistryClass = ErrorRegistryException::class;
46
    /** @var bool */
47
    protected $serialization = false;
48
    /** @var int */
49
    protected $enabledAttributes = PhpAttribute::JSON_POINTER
50
        | PhpAttribute::SCHEMA_NAME
51
        | PhpAttribute::REQUIRED
52
        | PhpAttribute::READ_WRITE_ONLY
53
        | PhpAttribute::DEPRECATED;
54

55
    /** @var DraftInterface | DraftFactoryInterface */
56
    protected $draft;
57

58
    /** @var ClassNameGeneratorInterface */
59
    protected $classNameGenerator;
60

61
    /** @var FilterInterface[] */
62
    protected $filter;
63
    /** @var FormatValidatorInterface[] */
64
    protected $formats;
65

66
    /**
67
     * GeneratorConfiguration constructor.
68
     */
69
    public function __construct()
2,285✔
70
    {
71
        $this->draft = new AutoDetectionDraft();
2,285✔
72
        $this->classNameGenerator = new ClassNameGenerator();
2,285✔
73

74
        // add all built-in filter and format validators
75
        $this->initFilter();
2,285✔
76
        $this->initFormatValidator();
2,285✔
77
    }
78

79
    /**
80
     * Add an additional filter
81
     *
82
     * @throws Exception
83
     * @throws InvalidFilterException
84
     */
85
    public function addFilter(FilterInterface ...$additionalFilter): self
2,285✔
86
    {
87
        foreach ($additionalFilter as $filter) {
2,285✔
88
            $this->validateFilterCallback(
2,285✔
89
                $filter->getFilter(),
2,285✔
90
                "Invalid filter callback for filter {$filter->getToken()}",
2,285✔
91
            );
2,285✔
92

93
            if ($filter instanceof TransformingFilterInterface) {
2,285✔
94
                $this->validateFilterCallback(
2,285✔
95
                    $filter->getSerializer(),
2,285✔
96
                    "Invalid serializer callback for filter {$filter->getToken()}"
2,285✔
97
                );
2,285✔
98
            }
99

100
            $this->filter[$filter->getToken()] = $filter;
2,285✔
101
        }
102

103
        return $this;
2,285✔
104
    }
105

106
    /**
107
     * Add an additional format
108
     */
109
    public function addFormat(string $formatKey, FormatValidatorInterface $format): self
5✔
110
    {
111
        $this->formats[$formatKey] = $format;
5✔
112

113
        return $this;
5✔
114
    }
115

116
    public function getFormat(string $formatKey): ?FormatValidatorInterface
6✔
117
    {
118
        return $this->formats[$formatKey] ?? null;
6✔
119
    }
120

121
    /**
122
     * @throws InvalidFilterException
123
     */
124
    private function validateFilterCallback(array $callback, string $message): void
2,285✔
125
    {
126
        if (
127
            !(count($callback) === 2) ||
2,285✔
128
            !is_string($callback[0]) ||
2,285✔
129
            !is_string($callback[1]) ||
2,285✔
130
            !is_callable($callback)
2,285✔
131
        ) {
132
            throw new InvalidFilterException($message);
14✔
133
        }
134
    }
135

136
    /**
137
     * Get a filter by the given token
138
     */
139
    public function getFilter(string $token): ?FilterInterface
159✔
140
    {
141
        return $this->filter[$token] ?? null;
159✔
142
    }
143

144
    public function getClassNameGenerator(): ClassNameGeneratorInterface
2,233✔
145
    {
146
        return $this->classNameGenerator;
2,233✔
147
    }
148

149
    public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGenerator): self
2,207✔
150
    {
151
        $this->classNameGenerator = $classNameGenerator;
2,207✔
152

153
        return $this;
2,207✔
154
    }
155

156
    public function getNamespacePrefix(): string
2,135✔
157
    {
158
        return $this->namespacePrefix;
2,135✔
159
    }
160

161
    public function setNamespacePrefix(string $namespacePrefix): self
42✔
162
    {
163
        $this->namespacePrefix = trim($namespacePrefix, '\\');
42✔
164

165
        return $this;
42✔
166
    }
167

168
    public function isDefaultArraysToEmptyArrayEnabled(): bool
538✔
169
    {
170
        return $this->defaultArraysToEmptyArray;
538✔
171
    }
172

173
    public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): self
5✔
174
    {
175
        $this->defaultArraysToEmptyArray = $defaultArraysToEmptyArray;
5✔
176

177
        return $this;
5✔
178
    }
179

180
    public function isImmutable(): bool
2,203✔
181
    {
182
        return $this->immutable;
2,203✔
183
    }
184

185
    public function setImmutable(bool $immutable): self
197✔
186
    {
187
        $this->immutable = $immutable;
197✔
188

189
        return $this;
197✔
190
    }
191

192
    public function denyAdditionalProperties(): bool
2,072✔
193
    {
194
        return $this->denyAdditionalProperties;
2,072✔
195
    }
196

197
    public function setDenyAdditionalProperties(bool $denyAdditionalProperties): self
10✔
198
    {
199
        $this->denyAdditionalProperties = $denyAdditionalProperties;
10✔
200

201
        return $this;
10✔
202
    }
203

204
    public function hasSerializationEnabled(): bool
2,234✔
205
    {
206
        return $this->serialization;
2,234✔
207
    }
208

209
    public function setSerialization(bool $serialization): self
57✔
210
    {
211
        $this->serialization = $serialization;
57✔
212

213
        return $this;
57✔
214
    }
215

216
    public function setOutputEnabled(bool $outputEnabled): self
2,236✔
217
    {
218
        $this->outputEnabled = $outputEnabled;
2,236✔
219

220
        return $this;
2,236✔
221
    }
222

223
    public function isOutputEnabled(): bool
2,151✔
224
    {
225
        return $this->outputEnabled;
2,151✔
226
    }
227

228
    public function collectErrors(): bool
2,127✔
229
    {
230
        return $this->collectErrors;
2,127✔
231
    }
232

233
    public function setCollectErrors(bool $collectErrors): self
1,419✔
234
    {
235
        $this->collectErrors = $collectErrors;
1,419✔
236

237
        return $this;
1,419✔
238
    }
239

240
    public function getErrorRegistryClass(): string
548✔
241
    {
242
        return $this->errorRegistryClass;
548✔
243
    }
244

245
    public function setErrorRegistryClass(string $errorRegistryClass): self
×
246
    {
247
        $this->errorRegistryClass = $errorRegistryClass;
×
248

249
        return $this;
×
250
    }
251

252
    public function getDraft(): DraftInterface | DraftFactoryInterface
2,236✔
253
    {
254
        return $this->draft;
2,236✔
255
    }
256

257
    public function setDraft(DraftInterface | DraftFactoryInterface $draft): self
7✔
258
    {
259
        $this->draft = $draft;
7✔
260

261
        return $this;
7✔
262
    }
263

264
    public function isImplicitNullAllowed(): bool
2,195✔
265
    {
266
        return $this->allowImplicitNull;
2,195✔
267
    }
268

269
    public function setImplicitNull(bool $allowImplicitNull): self
2,211✔
270
    {
271
        $this->allowImplicitNull = $allowImplicitNull;
2,211✔
272

273
        return $this;
2,211✔
274
    }
275

276
    private function initFilter(): void
2,285✔
277
    {
278
        $this
2,285✔
279
            ->addFilter(new DateTimeFilter())
2,285✔
280
            ->addFilter(new NotEmptyFilter())
2,285✔
281
            ->addFilter(new TrimFilter());
2,285✔
282
    }
283

284
    public function getEnabledAttributes(): int
2,233✔
285
    {
286
        return $this->enabledAttributes;
2,233✔
287
    }
288

NEW
289
    public function setEnabledAttributes(int $enabledAttributes): self
×
290
    {
NEW
291
        $this->enabledAttributes = $enabledAttributes | PhpAttribute::ALWAYS_ENABLED_ATTRIBUTES;
×
292

NEW
293
        return $this;
×
294
    }
295

296
    public function enableAttributes(int $attributes): self
1✔
297
    {
298
        $this->enabledAttributes = $this->enabledAttributes | $attributes;
1✔
299

300
        return $this;
1✔
301
    }
302

303
    public function disableAttributes(int $attributes): self
1✔
304
    {
305
        $this->enabledAttributes = $this->enabledAttributes & ~$attributes | PhpAttribute::ALWAYS_ENABLED_ATTRIBUTES;
1✔
306

307
        return $this;
1✔
308
    }
309

310
    // TODO: add builtin format validators
311
    private function initFormatValidator(): void
2,285✔
312
    {
313
    }
2,285✔
314
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc