From 71fd3670f4b75bfc29b8db7af46386ab4daf37c0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 14 Feb 2024 17:39:11 +0100 Subject: [PATCH] tidy up bool values --- .../Fixture/bool_default_false.php.inc | 2 +- .../Fixture/softdeleteable_gedmo.php.inc | 2 +- .../config/yaml_mapping/column_options.yml | 1 + .../yaml_mapping/gedmo_softdeletable.yml | 1 + ...oftDeletableClassAnnotationTransformer.php | 13 +++++------ .../Helper/NodeValueNormalizer.php | 23 +++++++++++++++++++ .../NodeFactory/ArrayItemNodeFactory.php | 5 +++- 7 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 rules/CodeQuality/Helper/NodeValueNormalizer.php diff --git a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/bool_default_false.php.inc b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/bool_default_false.php.inc index dcb9e8ee..a310de4e 100644 --- a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/bool_default_false.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/bool_default_false.php.inc @@ -19,7 +19,7 @@ namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\YamlToAnnotationsDoctr final class BoolDefaultFalse { /** - * @\Doctrine\ORM\Mapping\Column(type="boolean", options={"default"=false, "size"=100, "where"="name IS NULL"}) + * @\Doctrine\ORM\Mapping\Column(type="boolean", unique=true, options={"default"=false, "size"=100, "where"="name IS NULL"}) */ public $someProperty; } diff --git a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/softdeleteable_gedmo.php.inc b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/softdeleteable_gedmo.php.inc index 756c58c1..fd79299c 100644 --- a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/softdeleteable_gedmo.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/Fixture/softdeleteable_gedmo.php.inc @@ -13,7 +13,7 @@ final class SoftdeletableGedmo namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\YamlToAnnotationsDoctrineMappingRector\Fixture; /** - * @\Gedmo\Mapping\Annotation\SoftDeleteable(fieldName="deleted", timeAware="false") + * @\Gedmo\Mapping\Annotation\SoftDeleteable(fieldName="deleted", timeAware=false, someNumber=100) * @\Doctrine\ORM\Mapping\Table */ final class SoftdeletableGedmo diff --git a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/column_options.yml b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/column_options.yml index d9253251..add866d3 100644 --- a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/column_options.yml +++ b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/column_options.yml @@ -2,6 +2,7 @@ Rector\Doctrine\Tests\CodeQuality\Rector\Class_\YamlToAnnotationsDoctrineMapping fields: someProperty: type: boolean + unique: true options: default: false size: 100 diff --git a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/gedmo_softdeletable.yml b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/gedmo_softdeletable.yml index cccb98f5..1b7b85e3 100644 --- a/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/gedmo_softdeletable.yml +++ b/rules-tests/CodeQuality/Rector/Class_/YamlToAnnotationsDoctrineMappingRector/config/yaml_mapping/gedmo_softdeletable.yml @@ -3,3 +3,4 @@ Rector\Doctrine\Tests\CodeQuality\Rector\Class_\YamlToAnnotationsDoctrineMapping soft_deleteable: field_name: "deleted" time_aware: false + some_number: 100 diff --git a/rules/CodeQuality/AnnotationTransformer/ClassAnnotationTransformer/SoftDeletableClassAnnotationTransformer.php b/rules/CodeQuality/AnnotationTransformer/ClassAnnotationTransformer/SoftDeletableClassAnnotationTransformer.php index e779dd33..f96ed54a 100644 --- a/rules/CodeQuality/AnnotationTransformer/ClassAnnotationTransformer/SoftDeletableClassAnnotationTransformer.php +++ b/rules/CodeQuality/AnnotationTransformer/ClassAnnotationTransformer/SoftDeletableClassAnnotationTransformer.php @@ -5,10 +5,10 @@ namespace Rector\Doctrine\CodeQuality\AnnotationTransformer\ClassAnnotationTransformer; use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode; -use Rector\BetterPhpDocParser\PhpDoc\StringNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\Doctrine\CodeQuality\Contract\ClassAnnotationTransformerInterface; use Rector\Doctrine\CodeQuality\DocTagNodeFactory; +use Rector\Doctrine\CodeQuality\Helper\NodeValueNormalizer; use Rector\Doctrine\CodeQuality\Utils\CaseStringHelper; use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping; @@ -50,13 +50,12 @@ private function createArrayItemNodes(array $softDeletableMapping): array { $arrayItemNodes = []; - foreach ($softDeletableMapping as $fieldKey => $fieldValue) { - if (is_bool($fieldValue)) { - $fieldValue = $fieldValue ? 'true' : 'false'; - } + foreach ($softDeletableMapping as $fieldKey => $fieldValueNode) { + $fieldKey = CaseStringHelper::camelCase($fieldKey); - $camelCaseFieldKey = CaseStringHelper::camelCase($fieldKey); - $arrayItemNodes[] = new ArrayItemNode(new StringNode($fieldValue), $camelCaseFieldKey); + $fieldValueNode = NodeValueNormalizer::normalize($fieldValueNode); + + $arrayItemNodes[] = new ArrayItemNode($fieldValueNode, $fieldKey); } return $arrayItemNodes; diff --git a/rules/CodeQuality/Helper/NodeValueNormalizer.php b/rules/CodeQuality/Helper/NodeValueNormalizer.php new file mode 100644 index 00000000..80b753a2 --- /dev/null +++ b/rules/CodeQuality/Helper/NodeValueNormalizer.php @@ -0,0 +1,23 @@ +