Skip to content

Commit 5ec055a

Browse files
Geekimojrushlow
authored andcommitted
feat(entity): Add use of Doctrine types constants in attributes
1 parent b23178c commit 5ec055a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Resources/skeleton/doctrine/Entity.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class <?= $class_name."\n" ?>
1717
{
1818
#[ORM\Id]
1919
#[ORM\GeneratedValue]
20-
#[ORM\Column(type: 'integer')]
20+
#[ORM\Column(type: Types::INTEGER)]
2121
private int $id;
2222

2323
public function getId(): ?int

src/Util/ClassSourceManipulator.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,39 @@ private function getEntityTypeHint(string $doctrineType): ?string
10401040
};
10411041
}
10421042

1043+
private function getTypeConstant(string $type): string
1044+
{
1045+
$typesMapping = [
1046+
'array' => 'Types::ARRAY',
1047+
'ascii_string' => 'Types::ASCII_STRING',
1048+
'bigint' => 'Types::BIGINT',
1049+
'binary' => 'Types::BINARY',
1050+
'blob' => 'Types::BLOB',
1051+
'boolean' => 'Types::BOOLEAN',
1052+
'date' => 'Types::DATE_MUTABLE',
1053+
'date_immutable' => 'Types::DATE_IMMUTABLE',
1054+
'dateinterval' => 'Types::DATEINTERVAL',
1055+
'datetime' => 'Types::DATETIME_MUTABLE',
1056+
'datetime_immutable' => 'Types::DATETIME_IMMUTABLE',
1057+
'datetimetz' => 'Types::DATETIMETZ_MUTABLE',
1058+
'datetimetz_immutable' => 'Types::DATETIMETZ_IMMUTABLE',
1059+
'decimal' => 'Types::DECIMAL',
1060+
'float' => 'Types::FLOAT',
1061+
'guid' => 'Types::GUID',
1062+
'integer' => 'Types::INTEGER',
1063+
'json' => 'Types::JSON',
1064+
'object' => 'Types::OBJECT',
1065+
'simple_array' => 'Types::SIMPLE_ARRAY',
1066+
'smallint' => 'Types::SMALLINT',
1067+
'string' => 'Types::STRING',
1068+
'text' => 'Types::TEXT',
1069+
'time' => 'Types::TIME_MUTABLE',
1070+
'time_immutable' => 'Types::TIME_IMMUTABLE',
1071+
];
1072+
1073+
return $typesMapping[$type] ?? $type;
1074+
}
1075+
10431076
private function isInSameNamespace(string $class): bool
10441077
{
10451078
$namespace = substr($class, 0, strrpos($class, '\\'));

0 commit comments

Comments
 (0)