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

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

03 Apr 2026 01:24AM UTC coverage: 98.248% (-0.4%) from 98.654%
23929639588

Pull #125

github

Enno Woortmann
docs
Pull Request #125: attributes

1496 of 1526 new or added lines in 66 files covered. (98.03%)

4 existing lines in 3 files now uncovered.

4374 of 4452 relevant lines covered (98.25%)

620.23 hits per line

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

96.43
/src/Draft/Modifier/ObjectType/ObjectModifier.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Draft\Modifier\ObjectType;
6

7
use PHPModelGenerator\Draft\Modifier\ModifierInterface;
8
use PHPModelGenerator\Exception\SchemaException;
9
use PHPModelGenerator\Model\Property\BaseProperty;
10
use PHPModelGenerator\Model\Property\PropertyInterface;
11
use PHPModelGenerator\Model\Property\PropertyType;
12
use PHPModelGenerator\Model\Schema;
13
use PHPModelGenerator\Model\SchemaDefinition\JsonSchema;
14
use PHPModelGenerator\Model\Validator\InstanceOfValidator;
15
use PHPModelGenerator\PropertyProcessor\Decorator\Property\ObjectInstantiationDecorator;
16
use PHPModelGenerator\PropertyProcessor\Decorator\SchemaNamespaceTransferDecorator;
17
use PHPModelGenerator\SchemaProcessor\SchemaProcessor;
18

19
class ObjectModifier implements ModifierInterface
20
{
21
    /**
22
     * Wire the instantiation linkage for a nested object property.
23
     *
24
     * The nested Schema is already set on the property by PropertyFactory before the modifier
25
     * list runs. This modifier reads it and attaches ObjectInstantiationDecorator,
26
     * InstanceOfValidator, PropertyType, and namespace transfer decorators to the outer property.
27
     *
28
     * Skips for BaseProperty (root-level schema) — no instantiation is needed there.
29
     *
30
     * @throws SchemaException
31
     */
32
    public function modify(
2,123✔
33
        SchemaProcessor $schemaProcessor,
34
        Schema $schema,
35
        PropertyInterface $property,
36
        JsonSchema $propertySchema,
37
    ): void {
38
        if ($property instanceof BaseProperty) {
2,123✔
39
            return;
2,123✔
40
        }
41

42
        $nestedSchema = $property->getNestedSchema();
960✔
43
        if ($nestedSchema === null) {
960✔
NEW
44
            return;
×
45
        }
46

47
        if (
48
            $nestedSchema->getClassPath() !== $schema->getClassPath() ||
960✔
49
            $nestedSchema->getClassName() !== $schema->getClassName()
960✔
50
        ) {
51
            $schema->addUsedClass(
953✔
52
                join(
953✔
53
                    '\\',
953✔
54
                    array_filter([
953✔
55
                        $schemaProcessor->getGeneratorConfiguration()->getNamespacePrefix(),
953✔
56
                        $nestedSchema->getClassPath(),
953✔
57
                        $nestedSchema->getClassName(),
953✔
58
                    ]),
953✔
59
                )
953✔
60
            );
953✔
61

62
            $schema->addNamespaceTransferDecorator(new SchemaNamespaceTransferDecorator($nestedSchema));
953✔
63
        }
64

65
        $property
960✔
66
            ->addDecorator(
960✔
67
                new ObjectInstantiationDecorator(
960✔
68
                    $nestedSchema->getClassName(),
960✔
69
                    $schemaProcessor->getGeneratorConfiguration(),
960✔
70
                )
960✔
71
            )
960✔
72
            ->setType(new PropertyType($nestedSchema->getClassName()));
960✔
73

74
        $property->addValidator(new InstanceOfValidator($property), 3);
960✔
75
    }
76
}
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