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

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

28 Jul 2026 03:28AM UTC coverage: 98.734% (-0.01%) from 98.746%
30326073718

Pull #178

github

claude
Indent the new heredoc closing markers to match surrounding code

The library requires PHP >=8.4, so the flexible (PHP 7.3+) heredoc/nowdoc
syntax is always available - the rest of the codebase already relies on it.
The four heredocs added earlier in GeneratedCodeFormattingTest.php used the
old column-0 closing marker instead, out of habit from concurrent work on a
PHP 7.1-compatible library. Reindented to match the surrounding statement's
nesting level, consistent with the rest of the codebase.
Pull Request #178: Render generated code PSR-12 compatible

199 of 201 new or added lines in 23 files covered. (99.0%)

7176 of 7268 relevant lines covered (98.73%)

573.82 hits per line

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

96.3
/src/PropertyProcessor/Filter/FilterPreTransformGuardValidator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\PropertyProcessor\Filter;
6

7
use PHPMicroTemplate\Exception\PHPMicroTemplateException;
8
use PHPModelGenerator\Exception\RenderException;
9
use PHPModelGenerator\Model\GeneratorConfiguration;
10
use PHPModelGenerator\Model\MethodInterface;
11
use PHPModelGenerator\Model\Property\PropertyInterface;
12
use PHPModelGenerator\Model\Schema;
13
use PHPModelGenerator\Model\Validator\AbstractComposedPropertyValidator;
14
use PHPModelGenerator\Model\Validator\ExtractedMethodValidator;
15
use PHPModelGenerator\Utils\RenderHelper;
16

17
/**
18
 * Wraps an input-space composition validator with a skip guard that bypasses the entire
19
 * composition check when the property value is already in the filter's output type-space.
20
 * Keeps filter-specific mechanics entirely within the filter package.
21
 */
22
final class FilterPreTransformGuardValidator extends ExtractedMethodValidator
23
{
24
    public function __construct(
23✔
25
        GeneratorConfiguration $generatorConfiguration,
26
        PropertyInterface $property,
27
        private readonly AbstractComposedPropertyValidator $inner,
28
        private readonly string $skipCheck,
29
    ) {
30
        parent::__construct($generatorConfiguration, $property, '', [], '', []);
23✔
31
        $this->extractedMethodName = 'filterPreTransformGuard_' . $inner->getExtractedMethodName();
23✔
32
        $this->isResolved = true;
23✔
33
    }
34

35
    /**
36
     * Sets scope on both this guard and the wrapped inner validator, and registers the
37
     * inner validator's extracted method in the schema.
38
     *
39
     * RenderHelper::renderValidator() processes only validators that are directly in the
40
     * property's validators list. The inner wrapped validator is not on that list, so
41
     * RenderHelper never registers its extracted method automatically. The guard method's
42
     * generated code calls $this->innerMethodName by name, which must exist as a class
43
     * method. This block registers it manually; the hasMethod check prevents
44
     * double-registration when setScope() is called more than once on the same guard.
45
     *
46
     * $this->inner->setScope($schema) sets the inner validator's $scope field so that
47
     * its getCheck() can reference $this->scope during template rendering.
48
     */
49
    public function setScope(Schema $schema): void
23✔
50
    {
51
        parent::setScope($schema);
23✔
52
        $this->inner->setScope($schema);
23✔
53

54
        if (!$schema->hasMethod($this->inner->getExtractedMethodName())) {
23✔
55
            $schema->addMethod($this->inner->getExtractedMethodName(), $this->inner->getMethod());
23✔
56
        }
57
    }
58

59
    /**
60
     * Returns the wrapped input-space composition validator.
61
     */
62
    public function getInnerValidator(): AbstractComposedPropertyValidator
21✔
63
    {
64
        return $this->inner;
21✔
65
    }
66

67
    /**
68
     * Returns a method that short-circuits when the value is already in the filter's
69
     * output type-space, and otherwise delegates to the wrapped composition validator.
70
     */
71
    public function getMethod(): MethodInterface
23✔
72
    {
73
        return new class ($this) implements MethodInterface {
23✔
74
            public function __construct(private readonly FilterPreTransformGuardValidator $validator)
75
            {}
23✔
76

77
            public function getCode(): string
78
            {
79
                return $this->validator->renderGuardMethod();
23✔
80
            }
81
        };
23✔
82
    }
83

84
    /**
85
     * @throws RenderException
86
     */
87
    public function renderGuardMethod(): string
23✔
88
    {
89
        try {
90
            return $this->getRenderer()->renderTemplate(
23✔
91
                DIRECTORY_SEPARATOR . 'Validator' . DIRECTORY_SEPARATOR . 'FilterPreTransformGuard.phptpl',
23✔
92
                [
23✔
93
                    'guardMethodName' => $this->getExtractedMethodName(),
23✔
94
                    'innerMethodName' => $this->inner->getExtractedMethodName(),
23✔
95
                    'skipCheck' => $this->skipCheck,
23✔
96
                    'viewHelper' => new RenderHelper($this->generatorConfiguration),
23✔
97
                ],
23✔
98
            );
23✔
NEW
99
        } catch (PHPMicroTemplateException $exception) {
×
100
            // @codeCoverageIgnoreStart
101
            throw new RenderException(
102
                "Can't render filter pre-transform guard {$this->getExtractedMethodName()}",
103
                0,
104
                $exception,
105
            );
106
            // @codeCoverageIgnoreEnd
107
        }
108
    }
109
}
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