Skip to content

Commit b2d02b1

Browse files
committed
Remove double generated code
1 parent bcb6367 commit b2d02b1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ext-json": "*"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^8.0"
21+
"phpunit/phpunit": "^8.4"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/Templates/Model.phptpl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ class {{ class }}
122122
$this->errorRegistry = new {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}();
123123
{% endif%}
124124

125-
{% foreach property.getOrderedValidators() as validator %}
126-
{{ validator.getValidatorSetUp() }}
127-
if ({{ validator.getCheck() }}) {
128-
{{ viewHelper.validationError(validator.getExceptionMessage()) }}
129-
}
130-
{% endforeach %}
125+
$value = $this->validate{{ viewHelper.ucfirst(property.getAttribute()) }}($value, $modelData);
131126

132127
{% if generatorConfiguration.collectErrors() %}
133128
if ($this->errorRegistry->getErrors()) {
@@ -154,14 +149,22 @@ class {{ class }}
154149

155150
{{ viewHelper.resolvePropertyDecorator(property) }}
156151

152+
$this->{{ property.getAttribute() }} = $this->validate{{ viewHelper.ucfirst(property.getAttribute()) }}($value, $modelData);
153+
}
154+
155+
/**
156+
* Execute all validators for the property {{ property.getAttribute() }}
157+
*/
158+
protected function validate{{ viewHelper.ucfirst(property.getAttribute()) }}($value, array $modelData)
159+
{
157160
{% foreach property.getOrderedValidators() as validator %}
158161
{{ validator.getValidatorSetUp() }}
159162
if ({{ validator.getCheck() }}) {
160163
{{ viewHelper.validationError(validator.getExceptionMessage()) }}
161164
}
162165
{% endforeach %}
163166

164-
$this->{{ property.getAttribute() }} = $value;
167+
return $value;
165168
}
166169
{% endforeach %}
167170
}

0 commit comments

Comments
 (0)