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

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

31 Oct 2026 05:09PM UTC coverage: 44.303% (+6.3%) from 37.962%
41223134295

Pull #23

github

claude
Locate the errors of a schema dependency inside the object

InvalidSchemaDependencyException did not link the exceptions of the
dependency schema to the instance pointer chain at all. For
dependencies: {a: {required: [b]}} and the input {obj: {a: 1}} the
missing "b" was located at /b instead of /obj/b.

The dependency exception itself stays located at the property which
triggers the dependency (/obj/a), the same as
InvalidPropertyDependencyException. The dependency schema validates the
object owning that property, so its errors belong inside that object.
Simply linking them to the dependency exception would append the
triggering property to them (/obj/a/b), and dropping the exception's own
segment would move its pointer from the triggering property to the
object, away from the property dependency sibling.

ValidationException therefore distinguishes the segment an exception
contributes to its own pointer from the segment the exceptions nested
below it are resolved against. They are identical unless an exception
calls excludeOwnInstancePointerSegmentFromNestedErrors(), which the
schema dependency exception does. A segment assigned later by a wrapper
(an array index) is the real position of the object and applies to both.

The redundant class and constructor docblocks of the dependency
exception 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: tuple positions, additional tuple items, class-name placeholders, schema dependencies

25 of 25 new or added lines in 4 files covered. (100.0%)

8 existing lines in 2 files now uncovered.

451 of 1018 relevant lines covered (44.3%)

4.09 hits per line

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

85.19
/src/Exception/ComposedValue/InvalidComposedValueException.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Exception\ComposedValue;
6

7
use PHPModelGenerator\Exception\ErrorRegistryExceptionInterface;
8
use PHPModelGenerator\Exception\MessageFormatter;
9
use PHPModelGenerator\Exception\ValidationException;
10

11
/**
12
 * Class InvalidComposedValueException
13
 *
14
 * @package PHPModelGenerator\Exception\ComposedValue
15
 */
16
abstract class InvalidComposedValueException extends ValidationException
17
{
18
    protected const COMPOSED_ERROR_MESSAGE = '';
19
    /**
20
     * InvalidComposedValueException constructor.
21
     *
22
     * @param $providedValue
23
     * @param ValidationException[][] $compositionErrorCollection
24
     */
25
    public function __construct(
14 ✔
26
        $providedValue,
27
        string $propertyName,
28
        string $jsonPointer,
29
        protected int $succeededCompositionElements,
30
        protected array $compositionErrorCollection
31
    ) {
32
        // A composition branch validates the same value at the same position as the composition
33
        // itself — it consumes no path segment of its own, so branch errors only need the parent
34
        // link (not a segment replacement) to inherit wherever this composition ends up.
35
        foreach ($this->compositionErrorCollection as $branch) {
14 ✔
36
            foreach ($branch->getErrors() as $error) {
14 ✔
37
                $error->setInstancePointerParent($this);
13 ✔
38
            }
39
        }
40

41
        parent::__construct($this->getErrorMessage($propertyName), $propertyName, $providedValue, $jsonPointer);
14 ✔
42
    }
43

44
    public function getSucceededCompositionElements(): int
×
45
    {
46
        return $this->succeededCompositionElements;
×
47
    }
48

49
    /**
50
     * @return ValidationException[][]
51
     */
UNCOV
52
    public function getCompositionErrorCollection(): array
×
53
    {
UNCOV
54
        return $this->compositionErrorCollection;
×
55
    }
56

57
    protected function getErrorMessage(string $propertyName): string
14 ✔
58
    {
59
        $compositionIndex = 0;
14 ✔
60

61
        return "Invalid value for '$propertyName' declined by composition constraint\n  " .
14 ✔
62
            sprintf(
14 ✔
63
                static::COMPOSED_ERROR_MESSAGE,
14 ✔
64
                MessageFormatter::pluralize($this->succeededCompositionElements, 'element'),
14 ✔
65
            ) .
14 ✔
66
            array_reduce(
14 ✔
67
                $this->compositionErrorCollection,
14 ✔
68
                function (string $carry, ErrorRegistryExceptionInterface $exception) use (&$compositionIndex): string {
14 ✔
69
                    return "$carry\n  - Composition element #" . ++$compositionIndex . (
14 ✔
70
                        $exception->getErrors()
14 ✔
71
                            ? ": Failed\n    * " . MessageFormatter::bulletList($exception->getErrors())
13 ✔
72
                            : ': Valid'
14 ✔
73
                        );
14 ✔
74
                },
14 ✔
75
                ''
14 ✔
76
            );
14 ✔
77
    }
78
}
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