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

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

03 Jun 2026 08:37PM UTC coverage: 98.72% (+0.006%) from 98.714%
26912113495

push

github

wol-soft
Merge remote-tracking branch 'origin/master'

157 of 168 new or added lines in 9 files covered. (93.45%)

42 existing lines in 5 files now uncovered.

6172 of 6252 relevant lines covered (98.72%)

574.49 hits per line

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

67.27
/src/Model/Property/PropertyProxy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model\Property;
6

7
use PHPModelGenerator\Attributes\JsonPointer;
8
use PHPModelGenerator\Attributes\SchemaName;
9
use PHPModelGenerator\Exception\SchemaException;
10
use PHPModelGenerator\Model\Attributes\PhpAttribute;
11
use PHPModelGenerator\Model\GeneratorConfiguration;
12
use PHPModelGenerator\Model\Schema;
13
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
14
use PHPModelGenerator\Model\SchemaDefinition\ResolvedDefinitionsCollection;
15
use PHPModelGenerator\Model\Validator\PropertyValidatorInterface;
16
use PHPModelGenerator\PropertyProcessor\Decorator\Property\PropertyDecoratorInterface;
17
use PHPModelGenerator\PropertyProcessor\Decorator\TypeHint\TypeHintDecoratorInterface;
18

19
/**
20
 * Class PropertyProxy
21
 *
22
 * @package PHPModelGenerator\Model
23
 */
24
class PropertyProxy extends AbstractProperty
25
{
26
    private ?JsonSchema $overrideJsonSchema = null;
27
    private ?PhpAttribute $overrideJsonPointer = null;
28

29
    /**
30
     * PropertyProxy constructor.
31
     *
32
     * @param string $name The name must be provided separately as the name is not bound to the structure of a
33
     * referenced schema. Consequently, two properties with different names can refer an identical schema utilizing the
34
     * PropertyProxy. By providing a name to each of the proxies the resulting properties will get the correct names.
35
     *
36
     * @throws SchemaException
37
     */
38
    public function __construct(
955✔
39
        string $name,
40
        JsonSchema $jsonSchema,
41
        protected ResolvedDefinitionsCollection $definitionsCollection,
42
        protected string $key,
43
    ) {
44
        parent::__construct($name, $jsonSchema);
955✔
45
    }
46

47
    /**
48
     * Get the property out of the resolved definitions collection to proxy function calls
49
     */
50
    protected function getProperty(): PropertyInterface
955✔
51
    {
52
        return $this->definitionsCollection->offsetGet($this->key);
955✔
53
    }
54

55
    /**
56
     * @inheritdoc
57
     */
58
    public function getType(bool $outputType = false): ?PropertyType
230✔
59
    {
60
        return $this->getProperty()->getType($outputType);
230✔
61
    }
62

63
    /**
64
     * @inheritdoc
65
     */
66
    public function setType(
5✔
67
        ?PropertyType $type = null,
68
        ?PropertyType $outputType = null,
69
        bool $reset = false,
70
    ): PropertyInterface {
71
        $this->getProperty()->setType($type, $outputType, $reset);
5✔
72

73
        return $this;
5✔
74
    }
75

76
    /**
77
     * @inheritdoc
78
     */
79
    public function getTypeHint(bool $outputType = false, array $skipDecorators = []): string
444✔
80
    {
81
        return $this->getProperty()->getTypeHint($outputType, $skipDecorators);
444✔
82
    }
83

84
    /**
85
     * @inheritdoc
86
     */
87
    public function addTypeHintDecorator(TypeHintDecoratorInterface $typeHintDecorator): PropertyInterface
1✔
88
    {
89
        $this->getProperty()->addTypeHintDecorator($typeHintDecorator);
1✔
90

91
        return $this;
1✔
92
    }
93

94
    /**
95
     * @inheritdoc
96
     */
97
    public function getDescription(): string
15✔
98
    {
99
        return $this->getProperty()->getDescription();
15✔
100
    }
101

102
    public function getComment(): ?string
15✔
103
    {
104
        return $this->getProperty()->getComment();
15✔
105
    }
106

UNCOV
107
    public function setComment(string $comment): PropertyInterface
×
108
    {
UNCOV
109
        $this->getProperty()->setComment($comment);
×
110

UNCOV
111
        return $this;
×
112
    }
113

114
    public function getExamples(): array
15✔
115
    {
116
        return $this->getProperty()->getExamples();
15✔
117
    }
118

UNCOV
119
    public function setExamples(array $examples): PropertyInterface
×
120
    {
UNCOV
121
        $this->getProperty()->setExamples($examples);
×
122

UNCOV
123
        return $this;
×
124
    }
125

126
    /**
127
     * @inheritdoc
128
     */
129
    public function addValidator(
44✔
130
        PropertyValidatorInterface $validator,
131
        int $priority = 99,
132
        ?string $sourceKey = null,
133
    ): PropertyInterface {
134
        $this->getProperty()->addValidator($validator, $priority, $sourceKey);
44✔
135

136
        return $this;
44✔
137
    }
138

139
    /**
140
     * @inheritdoc
141
     */
142
    public function getValidators(): array
20✔
143
    {
144
        return $this->getProperty()->getValidators();
20✔
145
    }
146

147
    /**
148
     * @inheritdoc
149
     */
150
    public function filterValidators(callable $filter): PropertyInterface
942✔
151
    {
152
        $this->getProperty()->filterValidators($filter);
942✔
153

154
        return $this;
942✔
155
    }
156

157
    /**
158
     * @inheritdoc
159
     */
160
    public function getOrderedValidators(): array
933✔
161
    {
162
        return array_map(
933✔
163
            fn(PropertyValidatorInterface $propertyValidator): PropertyValidatorInterface =>
933✔
164
                $propertyValidator->withProperty($this),
933✔
165
            $this->getProperty()->getOrderedValidators(),
933✔
166
        );
933✔
167
    }
168

169
    /**
170
     * @inheritdoc
171
     */
UNCOV
172
    public function addDecorator(PropertyDecoratorInterface $decorator): PropertyInterface
×
173
    {
UNCOV
174
        $this->getProperty()->addDecorator($decorator);
×
175

UNCOV
176
        return $this;
×
177
    }
178

179
    /**
180
     * @inheritdoc
181
     */
UNCOV
182
    public function filterDecorators(callable $filter): PropertyInterface
×
183
    {
UNCOV
184
        $this->getProperty()->filterDecorators($filter);
×
185

UNCOV
186
        return $this;
×
187
    }
188

189
    /**
190
     * @inheritdoc
191
     */
192
    public function resolveDecorator(string $input, bool $nestedProperty): string
691✔
193
    {
194
        foreach ($this->getProperty()->getDecorators() as $decorator) {
691✔
195
            $input = $decorator->decorate($input, $this, $nestedProperty);
691✔
196
        }
197

198
        return $input;
691✔
199
    }
200

201
    /**
202
     * @inheritdoc
203
     */
204
    public function getDecorators(): array
933✔
205
    {
206
        return $this->getProperty()->getDecorators();
933✔
207
    }
208

209
    /**
210
     * @inheritdoc
211
     */
UNCOV
212
    public function setRequired(bool $isPropertyRequired): PropertyInterface
×
213
    {
UNCOV
214
        $this->getProperty()->setRequired($isPropertyRequired);
×
215

UNCOV
216
        return $this;
×
217
    }
218

219
    /**
220
     * @inheritdoc
221
     */
222
    public function isRequired(): bool
213✔
223
    {
224
        return $this->getProperty()->isRequired();
213✔
225
    }
226

227
    /**
228
     * @inheritdoc
229
     */
230
    public function setReadOnly(bool $isPropertyReadOnly): PropertyInterface
1✔
231
    {
232
        $this->getProperty()->setReadOnly($isPropertyReadOnly);
1✔
233

234
        return $this;
1✔
235
    }
236

237
    /**
238
     * @inheritdoc
239
     */
240
    public function isReadOnly(): bool
15✔
241
    {
242
        return $this->getProperty()->isReadOnly();
15✔
243
    }
244

245
    /**
246
     * @inheritdoc
247
     */
UNCOV
248
    public function setWriteOnly(bool $isPropertyWriteOnly): PropertyInterface
×
249
    {
UNCOV
250
        $this->getProperty()->setWriteOnly($isPropertyWriteOnly);
×
251

UNCOV
252
        return $this;
×
253
    }
254

255
    /**
256
     * @inheritdoc
257
     */
258
    public function isWriteOnly(): bool
15✔
259
    {
260
        return $this->getProperty()->isWriteOnly();
15✔
261
    }
262

263
    /**
264
     * @inheritdoc
265
     */
UNCOV
266
    public function setDefaultValue($defaultValue, bool $raw = false): PropertyInterface
×
267
    {
UNCOV
268
        $this->getProperty()->setDefaultValue($defaultValue, $raw);
×
269

UNCOV
270
        return $this;
×
271
    }
272

273
    /**
274
     * @inheritdoc
275
     */
276
    public function getDefaultValue(): ?string
19✔
277
    {
278
        return $this->getProperty()->getDefaultValue();
19✔
279
    }
280

281
    /**
282
     * @inheritdoc
283
     */
UNCOV
284
    public function setNestedSchema(Schema $schema): PropertyInterface
×
285
    {
UNCOV
286
        $this->getProperty()->setNestedSchema($schema);
×
287

UNCOV
288
        return $this;
×
289
    }
290

291
    /**
292
     * @inheritdoc
293
     */
294
    public function getNestedSchema(): ?Schema
847✔
295
    {
296
        return $this->getProperty()->getNestedSchema();
847✔
297
    }
298

299
    /**
300
     * @inheritdoc
301
     */
302
    public function getJsonSchema(): JsonSchema
5✔
303
    {
304
        return $this->overrideJsonSchema ?? $this->getProperty()->getJsonSchema();
5✔
305
    }
306

307
    /**
308
     * @inheritdoc
309
     *
310
     * Stores a local override rather than delegating to the underlying property, preventing
311
     * mutation of a shared $ref-resolved property when only this proxy's schema must change.
312
     */
NEW
313
    public function setJsonSchema(JsonSchema $jsonSchema): static
×
314
    {
NEW
315
        $this->overrideJsonSchema = $jsonSchema;
×
316

NEW
317
        return $this;
×
318
    }
319

320
    /**
321
     * @inheritdoc
322
     */
UNCOV
323
    public function setInternal(bool $isPropertyInternal): PropertyInterface
×
324
    {
UNCOV
325
        $this->getProperty()->setInternal($isPropertyInternal);
×
326

UNCOV
327
        return $this;
×
328
    }
329

330
    /**
331
     * @inheritdoc
332
     */
333
    public function isInternal(): bool
15✔
334
    {
335
        return $this->getProperty()->isInternal();
15✔
336
    }
337

338
    /**
339
     * @inheritdoc
340
     */
NEW
341
    public function filterAttributes(callable $filter): static
×
342
    {
NEW
343
        $this->getProperty()->filterAttributes($filter);
×
344

NEW
345
        return $this;
×
346
    }
347

348
    /**
349
     * @inheritdoc
350
     */
351
    public function addAttribute(
×
352
        PhpAttribute $attribute,
353
        ?GeneratorConfiguration $generatorConfiguration = null,
354
        ?int $enablementFlag = null,
355
    ): static {
UNCOV
356
        $this->getProperty()->addAttribute($attribute);
×
357

UNCOV
358
        return $this;
×
359
    }
360

361
    /**
362
     * Store the pointer attribute locally so this proxy can show a different JsonPointer from
363
     * the shared underlying property (each reference site has its own pointer).
364
     */
365
    public function overrideJsonPointer(PhpAttribute $attribute): static
114✔
366
    {
367
        $this->overrideJsonPointer = $attribute;
114✔
368

369
        return $this;
114✔
370
    }
371

372
    /**
373
     * @inheritdoc
374
     *
375
     * Replaces the SchemaName attribute from the underlying shared property with one that
376
     * carries the proxy's own name. Two proxies sharing the same $ref definition would
377
     * otherwise both report the first property's name via the shared underlying attribute.
378
     *
379
     * When a JsonPointer override is set, all existing JsonPointer attributes (there may be
380
     * multiple when the underlying property was synthesised from composition branches) are
381
     * removed and replaced with a single attribute pointing to the reference site.
382
     */
383
    public function getAttributes(): array
15✔
384
    {
385
        $attributes = array_map(
15✔
386
            fn(PhpAttribute $attribute): PhpAttribute => $attribute->getFqcn() === SchemaName::class
15✔
387
                ? new PhpAttribute(SchemaName::class, [$this->name])
15✔
388
                : $attribute,
15✔
389
            $this->getProperty()->getAttributes(),
15✔
390
        );
15✔
391

392
        if ($this->overrideJsonPointer !== null) {
15✔
393
            $attributes = array_values(array_filter(
15✔
394
                $attributes,
15✔
395
                static fn(PhpAttribute $attribute): bool => $attribute->getFqcn() !== JsonPointer::class,
15✔
396
            ));
15✔
397
            $attributes[] = $this->overrideJsonPointer;
15✔
398
        }
399

400
        return $attributes;
15✔
401
    }
402
}
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