-
Notifications
You must be signed in to change notification settings - Fork 10
Common interface for FunctionDeclarationNode and ClassMethodNode #180
Comments
Do you have a use case in mind? Also ideas for name of this interface? Functions and methods are similar in many ways, so in many ways it does make sense. With a method like a function except it belongs to a class and has visibility and static keyword. At the moment I have mostly just made interfaces to group nodes together as I have needed them and that fit the grammar. And as it is there a lot of classes/interfaces/traits. |
How about CallableNodeInterface? I think being able to type hint callable things would be quite handy. Plus, we could explicitly define common parameter and argument handling methods in it, for organization's sake. |
Would CallableNodeInterface also include anonymous functions? They don't have a name, so they are a bit different from functions and methods. What about MethodOrFunctionNodeInterface? A bit longer, but would avoid confusion. And then CallableNodeInterface could also include anonymous functions. Having these interfaces would allow to group together code that needs to work for of functions and methods. For example, we have an analyzer that checks the number of arguments in a function/method call. |
It would also be useful to have a common interface for ClassMethodNodes and InterfaceMethodNodes. Otherwise it's impossible to add type hints to parameters of methods that accept either type of a node. Also, ClassNode, InterfaceNode and TraitNode are used interchangeably in some cases and share similar properties. |
Agreed.. Just trying think of good names for these. Suggestions welcomed. Well ClassNode and TraitNode already share a common base class, SingleInheritanceNode |
What about ClassOrInterfaceMethodNode and ClassInterfaceOrTraitNode? |
FunctionDeclarationNode and ClassMethodNode both use FunctionTrait. It would be nice to add a common interface to these classes, so it would be possible to use it in type hints.
The text was updated successfully, but these errors were encountered: