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

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

27 Jul 2026 09:22PM UTC coverage: 98.599% (-0.1%) from 98.746%
30306608636

Pull #178

github

claude
Restructure dual-depth templates and migrate to php-micro-template's RenderConfig

Resolves the two remaining "dual-depth" template limitations by extracting
each shared body into its own sub-template, rendered via a nested
Render::renderTemplate() call and embedded with viewHelper.indent(): the
isMutableBaseValidator branch in ComposedItem.phptpl, and the
collectErrors(false) branch shared by SchemaDependency.phptpl and
Populate.phptpl. Pure rendering-mechanism change with no difference in the
generated PHP.

Migrates from the ad-hoc, locally-patched php-micro-template vendor copy to
the library's real RenderConfig/autoIndent feature, released as 1.12.0,
which is what the whole-suite phpcs formatting fixes in the prior commit
actually depend on for eliminating blank lines and getting correctly
indented, PSR-12-compliant generated code. Adds RenderFactory as the single
point of truth for constructing Render instances with autoIndent enabled,
caching by base path, replacing the per-class self::$renderer caching
that's now redundant.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PL4k3uwbW6xC2SjKNyjxFT
Pull Request #178: Fix generated-code formatting bugs found via whole-suite phpcs audit

199 of 211 new or added lines in 23 files covered. (94.31%)

7176 of 7278 relevant lines covered (98.6%)

573.03 hits per line

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

81.25
/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) {
×
NEW
100
            throw new RenderException(
×
NEW
101
                "Can't render filter pre-transform guard {$this->getExtractedMethodName()}",
×
NEW
102
                0,
×
NEW
103
                $exception,
×
NEW
104
            );
×
105
        }
106
    }
107
}
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