Skip to content

Commit c8d2a7f

Browse files
committed
Don't generate @Assert\Type by default
1 parent aeb1c5f commit c8d2a7f

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/AnnotationGenerator/ConstraintAnnotationGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function generateFieldAnnotations(string $className, string $fieldName):
5252
$asserts[] = '@Assert\Email';
5353
}
5454

55-
if (empty($asserts)) {
55+
if (!$asserts && $this->config['validator']['assertType']) {
5656
$phpType = $this->toPhpType($field);
5757
if (in_array($phpType, ['boolean', 'float', 'integer', 'string'], true)) {
5858
$asserts[] = sprintf('@Assert\Type(type="%s")', $phpType);

src/TypesGeneratorConfiguration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ function ($rdfa) {
9191
->scalarNode('resolveTargetEntityConfigPath')->defaultNull()->info('The Resolve Target Entity Listener config file pass')->end()
9292
->end()
9393
->end()
94+
->arrayNode('validator')
95+
->addDefaultsIfNotSet()
96+
->info('Symfony Validator Component')
97+
->children()
98+
->booleanNode('assertType')->defaultFalse()->info('Generate @Assert\Type annotation')->end()
99+
->end()
100+
->end()
94101
->scalarNode('author')->defaultFalse()->info('The value of the phpDoc\'s @author annotation')->example('Kévin Dunglas <[email protected]>')->end()
95102
->enumNode('fieldVisibility')->values(['private', 'protected', 'public'])->defaultValue('private')->cannotBeEmpty()->info('Visibility of entities fields')->end()
96103
->booleanNode('mutatorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end()

tests/Command/DumpConfigurationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ interface: AppBundle\Model # Example: Acme\Model
8383
# The Resolve Target Entity Listener config file pass
8484
resolveTargetEntityConfigPath: null
8585
86+
# Symfony Validator Component
87+
validator:
88+
89+
# Generate @Assert\Type annotation
90+
assertType: false
91+
8692
# The value of the phpDoc's @author annotation
8793
author: false # Example: Kévin Dunglas <[email protected]>
8894

0 commit comments

Comments
 (0)