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

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

16 Jul 2026 07:57PM UTC coverage: 46.172% (+24.6%) from 21.548%
29530702040

Pull #19

github

claude
Make enum/const messages self-descriptive

EnumException and InvalidConstException were the only constraint violations
that didn't say what would have satisfied them — "declined by enum
constraint" / "declined by const constraint" gave no indication of the
allowed/expected value or what was actually provided, unlike every other
constraint (Minimum, MaxLength, Pattern, Format, ...), which states its
bound directly in the message. Both getters (getAllowedValues(),
getExpectedValue()) already existed, but reading them meant an extra call
just to explain a common failure.

Messages now read "Value for 'x' must be <expected>, got <got>" (const) /
"... must be one of [<allowed>], got <got>" (enum). Values render through a
shared ValueFormatter (json_encode-based, with a var_export fallback for
values json_encode can't handle) since these are constraints on JSON data —
scalars, arrays, and objects all render consistently rather than needing
separate handling. Enum's allowed-values list is capped at 8 entries before
truncating to a 5-item preview + count, so a large enum doesn't turn the
message into a single unreadable line.
Pull Request #19: Fix nested composition indentation + add data-instance JSON pointer (issue #131)

79 of 81 new or added lines in 11 files covered. (97.53%)

1 existing line in 1 file now uncovered.

392 of 849 relevant lines covered (46.17%)

1.57 hits per line

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

81.08
/src/Exception/ComposedValue/ConditionalException.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Exception\ComposedValue;
6

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

11
/**
12
 * Class ConditionalException
13
 *
14
 * @package PHPModelGenerator\Exception\ComposedValue
15
 */
16
class ConditionalException extends ValidationException
17
{
18
    /**
19
     * ConditionalException constructor.
20
     *
21
     * @param $providedValue
22
     */
23
    public function __construct(
2✔
24
        $providedValue,
25
        string $propertyName,
26
        string $jsonPointer,
27
        private readonly ?Exception $ifException,
28
        private readonly ?Exception $thenException,
29
        private readonly ?Exception $elseException
30
    ) {
31
        // A conditional branch validates the same value at the same position as the conditional
32
        // itself — it consumes no path segment of its own, so branch errors only need the parent
33
        // link (not a segment replacement) to inherit wherever this conditional ends up.
34
        foreach ([$this->ifException, $this->thenException, $this->elseException] as $branchException) {
2✔
35
            $this->linkInstancePointerParent($branchException);
2✔
36
        }
37

38
        parent::__construct($this->getErrorMessage($propertyName), $propertyName, $providedValue, $jsonPointer);
2✔
39
    }
40

41
    private function linkInstancePointerParent(?Exception $exception): void
2✔
42
    {
43
        if ($exception instanceof ErrorRegistryExceptionInterface) {
2✔
44
            foreach ($exception->getErrors() as $error) {
1✔
45
                $error->setInstancePointerParent($this);
1✔
46
            }
47
        } elseif ($exception instanceof ValidationException) {
2✔
48
            $exception->setInstancePointerParent($this);
1✔
49
        }
50
    }
51

UNCOV
52
    public function getIfException(): ?Exception
×
53
    {
54
        return $this->ifException;
×
55
    }
56

57
    public function getThenException(): ?Exception
×
58
    {
59
        return $this->thenException;
×
60
    }
61

62
    public function getElseException(): ?Exception
×
63
    {
64
        return $this->elseException;
×
65
    }
66

67
    private function getErrorMessage(string $propertyName): string
2✔
68
    {
69
        $message = "Invalid value for $propertyName declined by conditional composition constraint\n";
2✔
70

71
        $message .= $this->ifException
2✔
72
            ? "  - Condition: Failed" . $this->getExceptionMessage($this->ifException)
×
73
            : '  - Condition: Valid';
2✔
74

75
        return $message . "\n  - Conditional branch failed:" .
2✔
76
            $this->getExceptionMessage($this->thenException ?: $this->elseException);
2✔
77
    }
78

79
    private function getExceptionMessage(Exception $exception): string
2✔
80
    {
81
        return $exception instanceof ErrorRegistryExceptionInterface
2✔
82
            ? implode(
1✔
83
                "\n    * ",
1✔
84
                str_replace(
1✔
85
                    "\n",
1✔
86
                    "\n    ",
1✔
87
                    array_map(
1✔
88
                        fn(ValidationException $exception): string => $exception->getMessage(),
1✔
89
                        $exception->getErrors(),
1✔
90
                    ),
1✔
91
                ),
1✔
92
            )
1✔
93
            : "\n    * " . str_replace("\n", "\n    ", $exception->getMessage());
2✔
94
    }
95
}
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