Override all object properties type to string #4216
-
I am author of hintable model fields for ORM project. The hintable magic works by hinting IDE
Example:
My question is, how to hint PHPStan, that:
is string but keep all other PHPStan checks like visibility, if property is defined etc. I think I need to write a PHPStan extension, but I would be very grateful to have some help/example to start with. Test cases:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
What object is returned when |
Beta Was this translation helpful? Give feedback.
-
So:
|
Beta Was this translation helpful? Give feedback.
-
Thanks to this guide, A little correction: Because you need |
Beta Was this translation helpful? Give feedback.
So:
User
in your example).Model::fieldName()
.new GenericObjectType(MagicModelField::Class, [new ObjectType('X')])
whenX::fieldName()
is called.PropertiesClassReflectionExtension
(https://phpstan.org/developing-extensions/class-reflection-extensions#properties-class-reflection-extensions) forMagicModelField
. In thehasProperty
method, you'll inspect the incoming ClassReflection (it should be for MagicModelField), and you'll ask aboutClassReflection::…