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

DoclerLabs / api-client-generator / 21418891888

27 Jan 2026 11:51PM UTC coverage: 86.69% (-0.3%) from 86.973%
21418891888

Pull #131

github

web-flow
Bump phpunit/phpunit from 9.5.9 to 9.6.33

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.9 to 9.6.33.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.33/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.9...9.6.33)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-version: 9.6.33
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #131: Bump phpunit/phpunit from 9.5.9 to 9.6.33

3465 of 3997 relevant lines covered (86.69%)

7.11 hits per line

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

67.35
/src/Generator/MutatorAccessorClassGeneratorAbstract.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Generator;
6

7
use DoclerLabs\ApiClientException\RequestValidationException;
8
use DoclerLabs\ApiClientGenerator\Ast\Builder\CodeBuilder;
9
use DoclerLabs\ApiClientGenerator\Entity\Constraint\ConstraintInterface;
10
use DoclerLabs\ApiClientGenerator\Entity\Constraint\MaxItemsConstraint;
11
use DoclerLabs\ApiClientGenerator\Entity\Constraint\MinItemsConstraint;
12
use DoclerLabs\ApiClientGenerator\Entity\Field;
13
use DoclerLabs\ApiClientGenerator\Input\Specification;
14
use DoclerLabs\ApiClientGenerator\Naming\SchemaNaming;
15
use DoclerLabs\ApiClientGenerator\Output\Php\PhpFileCollection;
16
use PhpParser\Node\Stmt\ClassMethod;
17
use PhpParser\Node\Stmt\Property;
18
use PhpParser\NodeAbstract;
19

20
abstract class MutatorAccessorClassGeneratorAbstract extends GeneratorAbstract
21
{
22
    protected CodeBuilder $builder;
23

24
    abstract public function generate(Specification $specification, PhpFileCollection $fileRegistry): void;
25

26
    protected function generateValidationStmts(Field $field): array
27
    {
28
        return array_filter(
2✔
29
            [
2✔
30
                ...$this->generateConstraints($field),
2✔
31
            ]
2✔
32
        );
2✔
33
    }
34

35
    /**
36
     * @param array<int, NodeAbstract> $additionalStatements
37
     */
38
    protected function generateSet(Field $field, array $additionalStatements = []): ClassMethod
39
    {
40
        $statements         = $this->generateValidationStmts($field);
2✔
41
        $thrownExceptionMap = empty($statements) ? [] : ['RequestValidationException' => true];
2✔
42
        $docType            = $field->getPhpDocType($field->isNullable());
2✔
43
        $param              = $this->builder
2✔
44
            ->param($field->getPhpVariableName())
2✔
45
            ->setType($field->getPhpTypeHint(), $field->isNullable())
2✔
46
            ->setDocBlockType($docType)
2✔
47
            ->getNode();
2✔
48

49
        $statements[] = $this->builder->assign(
2✔
50
            $this->builder->localPropertyFetch($field->getPhpVariableName()),
2✔
51
            $this->builder->var($field->getPhpVariableName())
2✔
52
        );
2✔
53

54
        $statements = array_merge($statements, $additionalStatements);
2✔
55

56
        $return     = $this->builder->return($this->builder->var('this'));
2✔
57
        $returnType = 'self';
2✔
58

59
        return $this->builder
2✔
60
            ->method($this->getSetMethodName($field))
2✔
61
            ->makePublic()
2✔
62
            ->addParam($param)
2✔
63
            ->addStmts($statements)
2✔
64
            ->addStmt($return)
2✔
65
            ->setReturnType($returnType)
2✔
66
            ->composeDocBlock([$param], $returnType, array_keys($thrownExceptionMap))
2✔
67
            ->getNode();
2✔
68
    }
69

70
    protected function generateGet(Field $field): ClassMethod
71
    {
72
        $return = $this->builder->return($this->builder->localPropertyFetch($field->getPhpVariableName()));
2✔
73

74
        return $this->builder
2✔
75
            ->method($this->getGetMethodName($field))
2✔
76
            ->makePublic()
2✔
77
            ->addStmt($return)
2✔
78
            ->setReturnType($field->getPhpTypeHint(), $field->isNullable() || !$field->isRequired())
2✔
79
            ->composeDocBlock([], $field->getPhpDocType())
2✔
80
            ->getNode();
2✔
81
    }
82

83
    protected function generateProperty(Field $field): Property
84
    {
85
        return $this->builder->localProperty(
2✔
86
            $field->getPhpVariableName(),
2✔
87
            $field->getPhpTypeHint(),
2✔
88
            $field->getPhpDocType(),
2✔
89
            nullable: $field->isOptional() || $field->isNullable(),
2✔
90
            readonly: $field->isRequired()
2✔
91
        );
2✔
92
    }
93

94
    protected function getSetMethodName(Field $field): string
95
    {
96
        return sprintf('set%s', ucfirst($field->getPhpVariableName()));
2✔
97
    }
98

99
    protected function getGetMethodName(Field $field): string
100
    {
101
        return sprintf('get%s', ucfirst($field->getPhpVariableName()));
2✔
102
    }
103

104
    protected function getHasMethodName(Field $field): string
105
    {
106
        return sprintf('has%s', ucfirst($field->getPhpVariableName()));
2✔
107
    }
108

109
    protected function generateEnumStatements(Field $field): array
110
    {
111
        if ($this->phpVersion->isEnumSupported()) {
2✔
112
            return [];
×
113
        }
114

115
        $statements = [];
2✔
116
        $enumValues = $field->isArrayOfEnums() ? $field->getArrayItem()->getEnumValues() : $field->getEnumValues();
2✔
117
        if (!empty($enumValues)) {
2✔
118
            foreach ($enumValues as $enumValue) {
2✔
119
                if (is_string($enumValue)) {
2✔
120
                    $constName = SchemaNaming::getEnumConstName($field, $enumValue);
2✔
121
                    if (preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $constName)) {
2✔
122
                        $statements[] = $this->builder->constant(
2✔
123
                            $constName,
2✔
124
                            $this->builder->val($enumValue)
2✔
125
                        );
2✔
126
                    }
127
                }
128
            }
129
        }
130

131
        return $statements;
2✔
132
    }
133

134
    protected function generateConstraints(Field $root): array
135
    {
136
        $stmts = [];
2✔
137

138
        /** @var ConstraintInterface $constraint */
139
        foreach ($root->getConstraints() as $constraint) {
2✔
140
            if (!$constraint->exists()) {
2✔
141
                continue;
2✔
142
            }
143

144
            $propertyVar = $this->builder->var($root->getPhpVariableName());
×
145

146
            if (
147
                $constraint instanceof MaxItemsConstraint
×
148
                || $constraint instanceof MinItemsConstraint
×
149
            ) {
150
                $exceptionMessage = $this->builder->funcCall(
×
151
                    'sprintf',
×
152
                    [
×
153
                        'Invalid %s value. ' . $constraint->getExceptionMessage(),
×
154
                        $root->getName(),
×
155
                    ]
×
156
                );
×
157
            } else {
158
                $exceptionMessage = $this->builder->funcCall(
×
159
                    'sprintf',
×
160
                    [
×
161
                        'Invalid %s value. Given: `%s`. ' . $constraint->getExceptionMessage(),
×
162
                        $root->getName(),
×
163
                        $propertyVar,
×
164
                    ]
×
165
                );
×
166
            }
167

168
            $ifConditionExpr = $constraint->getIfCondition($propertyVar, $this->builder);
×
169

170
            if ($root->isNullable()) {
×
171
                $ifConditionExpr = $this->builder->and(
×
172
                    $this->builder->notEquals($propertyVar, $this->builder->val(null)),
×
173
                    $ifConditionExpr
×
174
                );
×
175
            }
176

177
            $stmts[] = $this->builder->if(
×
178
                $ifConditionExpr,
×
179
                [
×
180
                    $this->builder->throw('RequestValidationException', $exceptionMessage),
×
181
                ]
×
182
            );
×
183
        }
184

185
        if (!empty($stmts)) {
2✔
186
            $this->addImport(RequestValidationException::class);
×
187
        }
188

189
        return $stmts;
2✔
190
    }
191
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc