Skip to content

Allow doctrine custom types to register their php class to makerbundle for generating Type Hint #1002

@sarim

Description

@sarim

Right now its hardcoded in

private function getEntityTypeHint($doctrineType): ?string
{
switch ($doctrineType) {
case 'string':
case 'text':
case 'guid':
case 'bigint':
case 'decimal':
return 'string';
case 'array':
case 'simple_array':
case 'json':
case 'json_array':
return 'array';
case 'boolean':
return 'bool';
case 'integer':
case 'smallint':
return 'int';
case 'float':
return 'float';
case 'datetime':
case 'datetimetz':
case 'date':
case 'time':
return '\\'.\DateTimeInterface::class;
case 'datetime_immutable':
case 'datetimetz_immutable':
case 'date_immutable':
case 'time_immutable':
return '\\'.\DateTimeImmutable::class;
case 'dateinterval':
return '\\'.\DateInterval::class;
case 'object':
case 'binary':
case 'blob':
default:
return null;
}
}

It would be useful to allow a configuration or any other way to allow user code to extend this type hint mappings. Right now for any fields of doctrine custom types, maker bundle does not generate any type hint for getter and setter methods. Which is expected as Doctrine\DBAL\Types\Type does not have any way to convey php object's type. Its cumbersome to manually add type hint to getter and setter, and its pointless as when regenerating entity (make:entity --regenerate --overwrite) its wiped out anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions