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

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

08 Apr 2026 12:29PM UTC coverage: 98.249% (-0.4%) from 98.654%
24135379642

Pull #125

github

wol-soft
CI
Pull Request #125: attributes

1507 of 1537 new or added lines in 73 files covered. (98.05%)

4 existing lines in 3 files now uncovered.

4376 of 4454 relevant lines covered (98.25%)

621.28 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,127✔
33
        SchemaProcessor $schemaProcessor,
34
        Schema $schema,
35
        PropertyInterface $property,
36
        JsonSchema $propertySchema,
37
    ): void {
38
        if ($property instanceof BaseProperty) {
2,127✔
39
            return;
2,127✔
40
        }
41

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

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

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

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

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