Open
Description
Versions:
- ide-helper Version: 3.5.5
- PHP Version: 8.4.7
Description:
Generating helper data for models that have methods with more complex return types currently fails.
Example:
class Test extends Model {
public function test(): (A&B)|null
}
What happens is this:
ModelCommand::getPropertiesFromMethods()
inspects all model methods to look for methods that implement something Laravel will interpret as an attribute- It calls
ModelCommand::getReturnTypeFromReflection()
to inspect the return type and, as far as I can see, flattennull
- The latter then calls
ModelCommand::extractReflectionTypes()
, which explodes on the example as it tries to callReflectionIntersectionType::getName()
The core issue is that extractReflectionTypes
assumes the type is either a simple named type or a union type of named types. Since php 8.1 types can get a lot more complex as union and intersection types can be nested.
Suggestions:
This looks like a very central and pretty hard and lengthy thing to thoroughly fix for all applications.
As a somewhat quick fix (as this blocks helper docs for the model) I think one of the following could work:
- Add a php attribute (e.g. IdeHelperIgnore) that the developer can add to a method and ide helper will then skip it. This would also need better error reporting. While this is certainly a band-aid solution, it could help quick-solving future issues.
- Check for the complexity of the return type and, if too complex, warn and skip the method
- Check for the complexity of the return type and, if too complex, fall back to
ReflectionType::__toString()
inModelCommand::getReturnTypeFromReflection()