orm
orm copied to clipboard
[QUESTION] Type hinting on autogenerated entities
Package version, Laravel version
v2.6.3
Expected behaviour
Type hints to be generated on methods which have a scalar type set
Actual behaviour
No type hints generated on methods
Steps to reproduce the behaviour
- Create a mapping configuration
- Generate entities
Hi all, I've recently started to use the ORM package and can see there's logic for creating type hints on methods whilst generating entities via the artisan command (EntityGenerator.php, line 1383).
if ($typeHint && ! isset($types[$typeHint])) {
$variableType = '\\' . ltrim($variableType, '\\');
$methodTypeHint = '\\' . $typeHint . ' ';
}
The above code seems to stop the entities generating as $types[$typeHint] is set, I've tested this using the following dd (dd($typeHint, isset($types[$typeHint]), $types);
) which produces:
"string"
true
array:26 [
"array" => "Doctrine\DBAL\Types\ArrayType"
"simple_array" => "Doctrine\DBAL\Types\SimpleArrayType"
"json_array" => "Doctrine\DBAL\Types\JsonArrayType"
"json" => "LaravelDoctrine\ORM\Types\Json"
"object" => "Doctrine\DBAL\Types\ObjectType"
"boolean" => "Doctrine\DBAL\Types\BooleanType"
"integer" => "Doctrine\DBAL\Types\IntegerType"
"smallint" => "Doctrine\DBAL\Types\SmallIntType"
"bigint" => "Doctrine\DBAL\Types\BigIntType"
"string" => "Doctrine\DBAL\Types\StringType"
"text" => "Doctrine\DBAL\Types\TextType"
"datetime" => "Doctrine\DBAL\Types\DateTimeType"
"datetime_immutable" => "Doctrine\DBAL\Types\DateTimeImmutableType"
"datetimetz" => "Doctrine\DBAL\Types\DateTimeTzType"
"datetimetz_immutable" => "Doctrine\DBAL\Types\DateTimeTzImmutableType"
"date" => "Doctrine\DBAL\Types\DateType"
"date_immutable" => "Doctrine\DBAL\Types\DateImmutableType"
"time" => "Doctrine\DBAL\Types\TimeType"
"time_immutable" => "Doctrine\DBAL\Types\TimeImmutableType"
"decimal" => "Doctrine\DBAL\Types\DecimalType"
"float" => "Doctrine\DBAL\Types\FloatType"
"binary" => "Doctrine\DBAL\Types\BinaryType"
"blob" => "Doctrine\DBAL\Types\BlobType"
"guid" => "Doctrine\DBAL\Types\GuidType"
"dateinterval" => "Doctrine\DBAL\Types\DateIntervalType"
"uuid" => "Ramsey\Uuid\Doctrine\UuidType"
]
The package is acting as the logic expects, but I'm wondering if there's something else I need to do to get type hints on my entities, or a reason I wouldn't want them?
Thanks
@dblencowe I think you should address this question to original doctrine devs here https://github.com/doctrine/orm since this package does not control the code of EntityGenerator.php
Also I need to mention that entity generation is deprecated and will be removed from v3.0 of doctrine