phpstan-doctrine
phpstan-doctrine copied to clipboard
When are custom type descriptors required?
Hello
I'm having a hard time figuring out if I need a custom type descriptor 🤔
My custom type is: https://github.com/assoconnect/doctrine-types-bundle/blob/master/src/Doctrine/DBAL/Types/EmailType.php
It extends Doctrine base String type so I guess:
- It doesn't need a custom type descriptor as I think that phpstan-doctrine can handle the base String type
- It does need a custom type descriptor as the base String type's
convertToPHPValue()
andconvertToDatabaseValue()
methods don't have proper type hints
=> Which one is it?
Whatever your answer is, you may consider improving this section of the README: https://github.com/phpstan/phpstan-doctrine#reflectiondescriptor
And thank you again for this awesome tool 🤩
Also, I'm wondering which type hints are required:
- Return type hint from both methods?
- Type hint of the
$value
argument for both methods?
Looking at the source code of ReflectionDescriptor
, I think the answer may be:
- Return type of the method
convertToPHPValue
- Type hint of argument
$value
for the methodconvertToDatabaseValue
But setting an argument type hint would trigger a "Declaration should be compatible with ..." error:
Should we just ignore this error? Or use an @param
annotation?
Thank you for your guidance