From fdaf8060a1fd4ae120d64106d5cf7a665bc6d7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sama=C3=ABl=20Tomas?= Date: Mon, 8 Sep 2025 15:11:15 +0200 Subject: [PATCH] Refactor enum handling in EntityColumnRule to improve type resolution --- src/Rules/Doctrine/ORM/EntityColumnRule.php | 38 ++++++++++----------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Rules/Doctrine/ORM/EntityColumnRule.php b/src/Rules/Doctrine/ORM/EntityColumnRule.php index 5a9f5fff..aa8343b7 100644 --- a/src/Rules/Doctrine/ORM/EntityColumnRule.php +++ b/src/Rules/Doctrine/ORM/EntityColumnRule.php @@ -105,26 +105,6 @@ public function processNode(Node $node, Scope $scope): array $writableToPropertyType = $descriptor->getWritableToPropertyType(); $writableToDatabaseType = $descriptor->getWritableToDatabaseType(); - if ($fieldMapping['type'] === 'enum') { - $values = $fieldMapping['options']['values'] ?? null; - if (is_array($values)) { - $enumTypes = []; - foreach ($values as $value) { - if (!is_string($value)) { - $enumTypes = []; - break; - } - - $enumTypes[] = new ConstantStringType($value); - } - - if (count($enumTypes) > 0) { - $writableToPropertyType = new UnionType($enumTypes); - $writableToDatabaseType = new UnionType($enumTypes); - } - } - } - $enumTypeString = $fieldMapping['enumType'] ?? null; if ($enumTypeString !== null) { if ($writableToDatabaseType->isArray()->no() && $writableToPropertyType->isArray()->no()) { @@ -179,6 +159,24 @@ public function processNode(Node $node, Scope $scope): array ), ...TypeUtils::getAccessoryTypes($writableToDatabaseType)); } + } elseif ($fieldMapping['type'] === 'enum') { + $values = $fieldMapping['options']['values'] ?? null; + if (is_array($values)) { + $enumTypes = []; + foreach ($values as $value) { + if (!is_string($value)) { + $enumTypes = []; + break; + } + + $enumTypes[] = new ConstantStringType($value); + } + + if (count($enumTypes) > 0) { + $writableToPropertyType = new UnionType($enumTypes); + $writableToDatabaseType = new UnionType($enumTypes); + } + } } $identifiers = [];