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

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

23 Mar 2026 01:55PM UTC coverage: 98.584% (-0.001%) from 98.585%
23440965067

Pull #118

github

Enno Woortmann
Merge fix/issue-110 into chore/phpunit-13-upgrade

Brings in patternProperties type intersection, PSR-12 code style
enforcement, PropertyMerger API refactor, and all related tests and
documentation. Resolved conflicts by keeping readonly constructors and
PHP 8.4+ style from this branch, applying phpcbf to align opening
braces with the PSR-12 rule. Added squizlabs/php_codesniffer to
require-dev alongside phpunit ^13.0.
Pull Request #118: Upgrade to PHP 8.4 minimum and PHPUnit 13

508 of 517 new or added lines in 54 files covered. (98.26%)

23 existing lines in 9 files now uncovered.

3828 of 3883 relevant lines covered (98.58%)

548.12 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model;
6

7
use Exception;
8
use PHPModelGenerator\Exception\InvalidFilterException;
9
use PHPModelGenerator\Filter\FilterInterface;
10
use PHPModelGenerator\Filter\TransformingFilterInterface;
11
use PHPModelGenerator\Format\FormatValidatorInterface;
12
use PHPModelGenerator\PropertyProcessor\Filter\DateTimeFilter;
13
use PHPModelGenerator\PropertyProcessor\Filter\NotEmptyFilter;
14
use PHPModelGenerator\PropertyProcessor\Filter\TrimFilter;
15
use PHPModelGenerator\Utils\ClassNameGenerator;
16
use PHPModelGenerator\Utils\ClassNameGeneratorInterface;
17
use PHPModelGenerator\Exception\ErrorRegistryException;
18

19
/**
20
 * Class GeneratorConfiguration
21
 *
22
 * @package PHPModelGenerator\Model
23
 */
24
class GeneratorConfiguration
25
{
26
    /** @var string */
27
    protected $namespacePrefix = '';
28
    /** @var bool */
29
    protected $immutable = true;
30
    /** @var bool */
31
    protected $allowImplicitNull = false;
32
    /** @var bool */
33
    protected $defaultArraysToEmptyArray = false;
34
    /** @var bool */
35
    protected $denyAdditionalProperties = false;
36
    /** @var bool */
37
    protected $outputEnabled = true;
38
    /** @var bool */
39
    protected $collectErrors = true;
40
    /** @var string */
41
    protected $errorRegistryClass = ErrorRegistryException::class;
42
    /** @var bool */
43
    protected $serialization = false;
44

45
    /** @var ClassNameGeneratorInterface */
46
    protected $classNameGenerator;
47

48
    /** @var FilterInterface[] */
49
    protected $filter;
50
    /** @var FormatValidatorInterface[] */
51
    protected $formats;
52

53
    /**
54
     * GeneratorConfiguration constructor.
55
     */
56
    public function __construct()
2,096✔
57
    {
58
        $this->classNameGenerator = new ClassNameGenerator();
2,096✔
59

60
        // add all built-in filter and format validators
61
        $this->initFilter();
2,096✔
62
        $this->initFormatValidator();
2,096✔
63
    }
64

65
    /**
66
     * Add an additional filter
67
     *
68
     * @throws Exception
69
     * @throws InvalidFilterException
70
     */
71
    public function addFilter(FilterInterface ...$additionalFilter): self
2,096✔
72
    {
73
        foreach ($additionalFilter as $filter) {
2,096✔
74
            $this->validateFilterCallback(
2,096✔
75
                $filter->getFilter(),
2,096✔
76
                "Invalid filter callback for filter {$filter->getToken()}",
2,096✔
77
            );
2,096✔
78

79
            if ($filter instanceof TransformingFilterInterface) {
2,096✔
80
                $this->validateFilterCallback(
2,096✔
81
                    $filter->getSerializer(),
2,096✔
82
                    "Invalid serializer callback for filter {$filter->getToken()}"
2,096✔
83
                );
2,096✔
84
            }
85

86
            foreach ($filter->getAcceptedTypes() as $acceptedType) {
2,096✔
87
                if (
88
                    !in_array($acceptedType, ['integer', 'number', 'boolean', 'string', 'array', 'null']) &&
2,096✔
89
                    !class_exists($acceptedType)
2,096✔
90
                ) {
91
                    throw new InvalidFilterException('Filter accepts invalid types');
1✔
92
                }
93
            }
94

95
            $this->filter[$filter->getToken()] = $filter;
2,096✔
96
        }
97

98
        return $this;
2,096✔
99
    }
100

101
    /**
102
     * Add an additional format
103
     */
104
    public function addFormat(string $formatKey, FormatValidatorInterface $format): self
5✔
105
    {
106
        $this->formats[$formatKey] = $format;
5✔
107

108
        return $this;
5✔
109
    }
110

111
    public function getFormat(string $formatKey): ?FormatValidatorInterface
6✔
112
    {
113
        return $this->formats[$formatKey] ?? null;
6✔
114
    }
115

116
    /**
117
     * @throws InvalidFilterException
118
     */
119
    private function validateFilterCallback(array $callback, string $message): void
2,096✔
120
    {
121
        if (
122
            !(count($callback) === 2) ||
2,096✔
123
            !is_string($callback[0]) ||
2,096✔
124
            !is_string($callback[1]) ||
2,096✔
125
            !is_callable($callback)
2,096✔
126
        ) {
127
            throw new InvalidFilterException($message);
14✔
128
        }
129
    }
130

131
    /**
132
     * Get a filter by the given token
133
     */
134
    public function getFilter(string $token): ?FilterInterface
136✔
135
    {
136
        return $this->filter[$token] ?? null;
136✔
137
    }
138

139
    public function getClassNameGenerator(): ClassNameGeneratorInterface
2,061✔
140
    {
141
        return $this->classNameGenerator;
2,061✔
142
    }
143

144
    public function setClassNameGenerator(ClassNameGeneratorInterface $classNameGenerator): self
2,053✔
145
    {
146
        $this->classNameGenerator = $classNameGenerator;
2,053✔
147

148
        return $this;
2,053✔
149
    }
150

151
    public function getNamespacePrefix(): string
1,982✔
152
    {
153
        return $this->namespacePrefix;
1,982✔
154
    }
155

156
    public function setNamespacePrefix(string $namespacePrefix): self
26✔
157
    {
158
        $this->namespacePrefix = trim($namespacePrefix, '\\');
26✔
159

160
        return $this;
26✔
161
    }
162

163
    public function isDefaultArraysToEmptyArrayEnabled(): bool
537✔
164
    {
165
        return $this->defaultArraysToEmptyArray;
537✔
166
    }
167

168
    public function setDefaultArraysToEmptyArray(bool $defaultArraysToEmptyArray): self
5✔
169
    {
170
        $this->defaultArraysToEmptyArray = $defaultArraysToEmptyArray;
5✔
171

172
        return $this;
5✔
173
    }
174

175
    public function isImmutable(): bool
1,996✔
176
    {
177
        return $this->immutable;
1,996✔
178
    }
179

180
    public function setImmutable(bool $immutable): self
182✔
181
    {
182
        $this->immutable = $immutable;
182✔
183

184
        return $this;
182✔
185
    }
186

187
    public function denyAdditionalProperties(): bool
1,922✔
188
    {
189
        return $this->denyAdditionalProperties;
1,922✔
190
    }
191

192
    public function setDenyAdditionalProperties(bool $denyAdditionalProperties): self
10✔
193
    {
194
        $this->denyAdditionalProperties = $denyAdditionalProperties;
10✔
195

196
        return $this;
10✔
197
    }
198

199
    public function hasSerializationEnabled(): bool
2,062✔
200
    {
201
        return $this->serialization;
2,062✔
202
    }
203

204
    public function setSerialization(bool $serialization): self
49✔
205
    {
206
        $this->serialization = $serialization;
49✔
207

208
        return $this;
49✔
209
    }
210

211
    public function setOutputEnabled(bool $outputEnabled): self
2,064✔
212
    {
213
        $this->outputEnabled = $outputEnabled;
2,064✔
214

215
        return $this;
2,064✔
216
    }
217

218
    public function isOutputEnabled(): bool
1,998✔
219
    {
220
        return $this->outputEnabled;
1,998✔
221
    }
222

223
    public function collectErrors(): bool
1,980✔
224
    {
225
        return $this->collectErrors;
1,980✔
226
    }
227

228
    public function setCollectErrors(bool $collectErrors): self
1,269✔
229
    {
230
        $this->collectErrors = $collectErrors;
1,269✔
231

232
        return $this;
1,269✔
233
    }
234

235
    public function getErrorRegistryClass(): string
530✔
236
    {
237
        return $this->errorRegistryClass;
530✔
238
    }
239

UNCOV
240
    public function setErrorRegistryClass(string $errorRegistryClass): self
×
241
    {
242
        $this->errorRegistryClass = $errorRegistryClass;
×
243

244
        return $this;
×
245
    }
246

247
    public function isImplicitNullAllowed(): bool
2,018✔
248
    {
249
        return $this->allowImplicitNull;
2,018✔
250
    }
251

252
    public function setImplicitNull(bool $allowImplicitNull): self
2,056✔
253
    {
254
        $this->allowImplicitNull = $allowImplicitNull;
2,056✔
255

256
        return $this;
2,056✔
257
    }
258

259
    private function initFilter(): void
2,096✔
260
    {
261
        $this
2,096✔
262
            ->addFilter(new DateTimeFilter())
2,096✔
263
            ->addFilter(new NotEmptyFilter())
2,096✔
264
            ->addFilter(new TrimFilter());
2,096✔
265
    }
266

267
    // TODO: add builtin format validators
268
    private function initFormatValidator(): void
2,096✔
269
    {
270
    }
2,096✔
271
}
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