From c8d2a7fbfe8d83f613b583ca78a09b32690ac87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 29 Aug 2017 21:31:49 +0200 Subject: [PATCH] Don't generate @Assert\Type by default --- src/AnnotationGenerator/ConstraintAnnotationGenerator.php | 2 +- src/TypesGeneratorConfiguration.php | 7 +++++++ tests/Command/DumpConfigurationTest.php | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/AnnotationGenerator/ConstraintAnnotationGenerator.php b/src/AnnotationGenerator/ConstraintAnnotationGenerator.php index 4ac37b8f..d229ec8f 100644 --- a/src/AnnotationGenerator/ConstraintAnnotationGenerator.php +++ b/src/AnnotationGenerator/ConstraintAnnotationGenerator.php @@ -52,7 +52,7 @@ public function generateFieldAnnotations(string $className, string $fieldName): $asserts[] = '@Assert\Email'; } - if (empty($asserts)) { + if (!$asserts && $this->config['validator']['assertType']) { $phpType = $this->toPhpType($field); if (in_array($phpType, ['boolean', 'float', 'integer', 'string'], true)) { $asserts[] = sprintf('@Assert\Type(type="%s")', $phpType); diff --git a/src/TypesGeneratorConfiguration.php b/src/TypesGeneratorConfiguration.php index 3e7daba8..88a0a530 100644 --- a/src/TypesGeneratorConfiguration.php +++ b/src/TypesGeneratorConfiguration.php @@ -91,6 +91,13 @@ function ($rdfa) { ->scalarNode('resolveTargetEntityConfigPath')->defaultNull()->info('The Resolve Target Entity Listener config file pass')->end() ->end() ->end() + ->arrayNode('validator') + ->addDefaultsIfNotSet() + ->info('Symfony Validator Component') + ->children() + ->booleanNode('assertType')->defaultFalse()->info('Generate @Assert\Type annotation')->end() + ->end() + ->end() ->scalarNode('author')->defaultFalse()->info('The value of the phpDoc\'s @author annotation')->example('Kévin Dunglas ')->end() ->enumNode('fieldVisibility')->values(['private', 'protected', 'public'])->defaultValue('private')->cannotBeEmpty()->info('Visibility of entities fields')->end() ->booleanNode('mutatorMethods')->defaultTrue()->info('Set this flag to false to not generate getter, setter, adder and remover methods')->end() diff --git a/tests/Command/DumpConfigurationTest.php b/tests/Command/DumpConfigurationTest.php index 88f36e01..dc1556ae 100644 --- a/tests/Command/DumpConfigurationTest.php +++ b/tests/Command/DumpConfigurationTest.php @@ -83,6 +83,12 @@ interface: AppBundle\Model # Example: Acme\Model # The Resolve Target Entity Listener config file pass resolveTargetEntityConfigPath: null + # Symfony Validator Component + validator: + + # Generate @Assert\Type annotation + assertType: false + # The value of the phpDoc's @author annotation author: false # Example: Kévin Dunglas