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

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

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

Pull #178

github

claude
Remove dead code and its explanatory comment from BuilderClass.phptpl

The @throws block for a builder setter's validators is unreachable code, not
just a documented limitation: BuilderClassPostProcessor unconditionally
strips every validator from builder properties via
filterValidators(fn() => false), so property.getValidators() can never be
non-empty in this template. Removed the block entirely instead of keeping a
dead branch alive "for whenever that changes" - if validators are ever
un-stripped, the @throws line can be reintroduced then, informed by whatever
that change actually needs.

Also drops the description-block comment explaining the standalone-if
choice - the pattern is now used pervasively across every class-emitting
template and no longer needs a per-callsite justification.
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.43
/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) {
×
74
            // @codeCoverageIgnoreStart
75
            throw new RenderException(
76
                "Can't render extracted method {$this->getExtractedMethodName()}",
77
                0,
78
                $exception,
79
            );
80
            // @codeCoverageIgnoreEnd
81
        }
82
    }
83

84
    public function getExtractedMethodName(): string
850✔
85
    {
86
        return $this->extractedMethodName;
850✔
87
    }
88
}
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