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

wol-soft / php-json-schema-model-generator-production / 41222324654

31 Oct 2026 04:59PM UTC coverage: 39.421% (+1.5%) from 37.962%
41222324654

Pull #23

github

claude
Keep the array name in the instance pointer of invalid additional tuple items

InvalidAdditionalTupleItemsException inherited the unconditional removal
of the exception's own instance pointer segment from
InvalidAdditionalPropertiesException. That removal is only correct for the
additionalProperties constraint of an object, where the property name is
the generated class name and serves as message label only. Additional
tuple items are validated by the array property itself and receive the
real array property name, so for the tuple "pair" with the input
['a', 1, 2, 'x'] the exception was located at "" and the nested error at
/3 instead of /pair and /pair/3. The keys already are the true array
indices.

The base class now suppresses its own segment only while
PROPERTY_NAME_IS_PLACEHOLDER is true; InvalidAdditionalTupleItemsException
sets it to false. The behaviour of the object exceptions (additional,
pattern, unevaluated properties and property names) is unchanged. The
redundant class and constructor docblocks of the touched exceptions are
removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U1R7TJejqtBJGe1uPS2p1L
Pull Request #23: Fix instance pointers of nested tuple errors and invalid additional tuple items

11 of 16 new or added lines in 4 files covered. (68.75%)

12 existing lines in 3 files now uncovered.

395 of 1002 relevant lines covered (39.42%)

2.35 hits per line

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

80.95
/src/Exception/ValidationException.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Exception;
6

7
use PHPModelGenerator\Attributes\JsonPointer;
8
use Throwable;
9

10
/**
11
 * Class ValidationException
12
 *
13
 * @package PHPModelGeneratorException
14
 */
15
abstract class ValidationException extends JSONModelValidationException
16
{
17
    private string $instancePointerSegment;
18
    private ?ValidationException $instancePointerParent = null;
19

20
    /**
21
     * ValidationException constructor.
22
     *
23
     * @param int $code
24
     */
25
    public function __construct(
43 ✔
26
        string $message,
27
        protected string $propertyName,
28
        protected mixed $providedValue,
29
        protected string $jsonPointer,
30
        $code = 0,
31
        ?Throwable $previous = null
32
    ) {
33
        parent::__construct($message, $code, $previous);
43 ✔
34

35
        $this->instancePointerSegment = '/' . self::escapeInstancePointerSegment($propertyName);
43 ✔
36
    }
37

38
    public function getPropertyName(): string
1 ✔
39
    {
40
        return $this->propertyName;
1 ✔
41
    }
42

43
    /**
44
     * @return mixed
45
     */
UNCOV
46
    public function getProvidedValue()
×
47
    {
UNCOV
48
        return $this->providedValue;
×
49
    }
50

51
    /**
52
     * The JSON pointer to the schema location of the constraint that rejected the value.
53
     */
UNCOV
54
    public function getJsonPointer(): JsonPointer
×
55
    {
UNCOV
56
        return new JsonPointer($this->jsonPointer);
×
57
    }
58

59
    /**
60
     * The JSON pointer (RFC 6901) to this value's location within the validated data instance
61
     * (e.g. "/goals/0/kind"), as opposed to getJsonPointer() which points into the schema.
62
     *
63
     * Resolved lazily by walking the parent chain set up via setInstancePointerParent(), so a
64
     * wrapper added after this exception was constructed (e.g. an array item later found to be
65
     * nested inside another array) is still reflected correctly.
66
     */
67
    public function getInstancePointer(): JsonPointer
19 ✔
68
    {
69
        return new JsonPointer(
19 ✔
70
            ($this->instancePointerParent?->getInstancePointer()->pointer ?? '') . $this->instancePointerSegment
19 ✔
71
        );
19 ✔
72
    }
73

74
    /**
75
     * Link this exception's instance pointer to continue from an enclosing exception's, as
76
     * exceptions bubble up from the point of failure to the root. Called by wrapping exceptions
77
     * (InvalidItemException, InvalidTupleException, InvalidAdditionalPropertiesException,
78
     * InvalidPatternPropertiesException, NestedObjectException, InvalidComposedValueException,
79
     * ConditionalException) on the nested exceptions they collect.
80
     *
81
     * Pass $segment when this exception's own propertyName is a placeholder shared by every
82
     * instance of an enclosing collection (an array item, an additional/pattern property) rather
83
     * than this value's real position — it replaces the auto-seeded segment with the caller's
84
     * actual position (an array index, the real property key). Omit it when this exception's own
85
     * propertyName is already a real, distinct name (composition branches, conditional branches,
86
     * and nested object properties all keep their own name and only need the parent link).
87
     */
88
    public function setInstancePointerParent(ValidationException $parent, int|string|null $segment = null): void
23 ✔
89
    {
90
        $this->instancePointerParent = $parent;
23 ✔
91

92
        if ($segment !== null) {
23 ✔
93
            $this->instancePointerSegment = '/' . self::escapeInstancePointerSegment((string) $segment);
20 ✔
94
        }
95
    }
96

97
    /**
98
     * Clear this exception's own instance pointer segment, leaving only whatever a parent link
99
     * (set via setInstancePointerParent()) contributes. Used by exceptions whose propertyName is
100
     * a class-name placeholder rather than a real instance-path segment: base validators that
101
     * validate the current object itself (additionalProperties/patternProperties checks) run
102
     * inside the generated class's own code, with no access to the property name their parent
103
     * used to reach this object, so they fall back to the class name purely for message text.
104
     */
105
    protected function suppressOwnInstancePointerSegment(): void
3 ✔
106
    {
107
        $this->instancePointerSegment = '';
3 ✔
108
    }
109

110
    private static function escapeInstancePointerSegment(string $segment): string
43 ✔
111
    {
112
        return str_replace(['~', '/'], ['~0', '~1'], $segment);
43 ✔
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc