• 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.82
/src/Model/Validator/ExtractedMethodValidator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Model\Validator;
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\Utils\RenderHelper;
13

14
/**
15
 * Renders the validator in a separate method. Might be required for recursive validations which would otherwise cause
16
 * infinite loops during validator rendering
17
 */
18
abstract class ExtractedMethodValidator extends PropertyTemplateValidator
19
{
20
    protected string $extractedMethodName;
21

22
    public function __construct(
1,246✔
23
        protected readonly GeneratorConfiguration $generatorConfiguration,
24
        PropertyInterface $property,
25
        string $template,
26
        array $templateValues,
27
        string $exceptionClass,
28
        array $exceptionParams = [],
29
    ) {
30
        $this->extractedMethodName = sprintf(
1,246✔
31
            '_validate%s_%s_%s',
1,246✔
32
            str_replace(' ', '', ucfirst($property->getAttribute())),
1,246✔
33
            str_replace('Validator', '', substr(strrchr(static::class, '\\'), 1)),
1,246✔
34
            md5(json_encode($property->getJsonSchema()->getJson())),
1,246✔
35
        );
1,246✔
36

37
        parent::__construct($property, $template, $templateValues, $exceptionClass, $exceptionParams);
1,246✔
38
    }
39

40
    public function getMethod(): MethodInterface
850✔
41
    {
42
        return new class ($this, $this->generatorConfiguration) implements MethodInterface {
850✔
43
            public function __construct(
44
                private readonly ExtractedMethodValidator $validator,
45
                private readonly GeneratorConfiguration $generatorConfiguration,
46
            ) {}
850✔
47

48
            public function getCode(): string
49
            {
50
                return $this->validator->renderExtractedMethod($this->generatorConfiguration);
850✔
51
            }
52
        };
850✔
53
    }
54

55
    /**
56
     * @throws RenderException
57
     */
58
    public function renderExtractedMethod(GeneratorConfiguration $generatorConfiguration): string
850✔
59
    {
60
        $renderHelper = new RenderHelper($generatorConfiguration);
850✔
61

62
        try {
63
            return $this->getRenderer()->renderTemplate(
850✔
64
                DIRECTORY_SEPARATOR . 'Validator' . DIRECTORY_SEPARATOR . 'ExtractedMethod.phptpl',
850✔
65
                [
850✔
66
                    'methodName' => $this->getExtractedMethodName(),
850✔
67
                    'setUp' => $this->getValidatorSetUp(),
850✔
68
                    'check' => $this->getCheck(),
850✔
69
                    'errorHandling' => $renderHelper->validationError($this),
850✔
70
                    'viewHelper' => $renderHelper,
850✔
71
                ],
850✔
72
            );
850✔
NEW
73
        } catch (PHPMicroTemplateException $exception) {
×
NEW
74
            throw new RenderException(
×
NEW
75
                "Can't render extracted method {$this->getExtractedMethodName()}",
×
NEW
76
                0,
×
NEW
77
                $exception,
×
NEW
78
            );
×
79
        }
80
    }
81

82
    public function getExtractedMethodName(): string
850✔
83
    {
84
        return $this->extractedMethodName;
850✔
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