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

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

18 Jul 2026 01:22AM UTC coverage: 44.717% (+23.2%) from 21.548%
29625079075

Pull #19

github

claude
Extract repeated message-assembly logic into MessageFormatter

Six exception classes duplicated the same "indent a sibling exception's
message and join under a bullet" idiom (InvalidItemException,
InvalidTupleException, InvalidAdditionalPropertiesException,
InvalidPatternPropertiesException, InvalidComposedValueException,
ConditionalException); two more had byte-for-byte identical logic for a
different case, flattening one arbitrary nested exception's whole message
into bullets one level deeper (NestedObjectException,
InvalidSchemaDependencyException); three more repeated a "quote each item
and join" idiom for flat lists (InvalidTypeException, AdditionalProperties-
Exception, InvalidPropertyDependencyException).

Renamed ValueFormatter to MessageFormatter and added bulletList(),
flattenNestedMessage() and quotedList() alongside the existing format(),
so every exception class assembling a message reaches for the same shared
helpers instead of re-implementing str_replace/implode/preg_replace calls.

Purely a refactor: every call site's exact output is unchanged (verified
via the full existing suite, no test assertions needed updating), plus new
MessageFormatterTest coverage for the extracted methods directly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZUchCwdY9cQFvyEXWnTZw
Pull Request #19: Fix nested composition indentation + add data-instance JSON pointer (issue #131)

101 of 138 new or added lines in 39 files covered. (73.19%)

2 existing lines in 2 files now uncovered.

364 of 814 relevant lines covered (44.72%)

1.8 hits per line

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

74.07
/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\MessageFormatter;
10
use PHPModelGenerator\Exception\ValidationException;
11

12
/**
13
 * Class ConditionalException
14
 *
15
 * @package PHPModelGenerator\Exception\ComposedValue
16
 */
17
class ConditionalException extends ValidationException
18
{
19
    /**
20
     * ConditionalException constructor.
21
     *
22
     * @param $providedValue
23
     */
24
    public function __construct(
2✔
25
        $providedValue,
26
        string $propertyName,
27
        string $jsonPointer,
28
        private readonly ?Exception $ifException,
29
        private readonly ?Exception $thenException,
30
        private readonly ?Exception $elseException
31
    ) {
32
        // A conditional branch validates the same value at the same position as the conditional
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 conditional ends up.
35
        foreach ([$this->ifException, $this->thenException, $this->elseException] as $branchException) {
2✔
36
            $this->linkInstancePointerParent($branchException);
2✔
37
        }
38

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

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

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

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

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

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

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

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

80
    private function getExceptionMessage(Exception $exception): string
2✔
81
    {
82
        return $exception instanceof ErrorRegistryExceptionInterface
2✔
83
            ? MessageFormatter::bulletList($exception->getErrors())
1✔
84
            : "\n    * " . str_replace("\n", "\n    ", $exception->getMessage());
2✔
85
    }
86
}
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