Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Common interface for FunctionDeclarationNode and ClassMethodNode #180

Open
pako-pl opened this issue Nov 3, 2014 · 6 comments
Open

Common interface for FunctionDeclarationNode and ClassMethodNode #180

pako-pl opened this issue Nov 3, 2014 · 6 comments

Comments

@pako-pl
Copy link

pako-pl commented Nov 3, 2014

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.

@grom358
Copy link
Owner

grom358 commented Nov 3, 2014

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.

@phenaproxima
Copy link
Collaborator

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.

@pako-pl
Copy link
Author

pako-pl commented Nov 3, 2014

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.

@pako-pl
Copy link
Author

pako-pl commented Nov 4, 2014

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.

@grom358
Copy link
Owner

grom358 commented Nov 4, 2014

Agreed.. Just trying think of good names for these. Suggestions welcomed.

Well ClassNode and TraitNode already share a common base class, SingleInheritanceNode

@pako-pl
Copy link
Author

pako-pl commented Nov 14, 2014

What about ClassOrInterfaceMethodNode and ClassInterfaceOrTraitNode?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants