Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectDeclarations::getFunctions() #124

Closed
GaryJones opened this issue Mar 29, 2020 · 2 comments · Fixed by #592
Closed

ObjectDeclarations::getFunctions() #124

GaryJones opened this issue Mar 29, 2020 · 2 comments · Fixed by #592

Comments

@GaryJones
Copy link
Contributor

Idea: Have a way to check if a class contains a particular method.

Class::containsMethod( string $class, string $method_name );

Instead of a string $class, perhaps a $stackPtr could be used instead.

@jrfnl
Copy link
Member

jrfnl commented Mar 29, 2020

This is related to something I have been thinking about already: a method to retrieve the method names of all methods declared in a class.

The code would then becomes something like:

$methods = Class::getMethodNames($phpcsFile, $stackPtr);
if (isset($methods[$targetMethod])) {
    // Do something.
}

Just keep in mind that any utility method which has to walk a large chunk of code is highly inefficient.

So, again, my question is: can you make the use-case more specific ? Can you give some examples of sniffs for which this would be useful ?

It might be better to create an abstract class as a base instead.

@jrfnl jrfnl added this to the 1.1.0 milestone Jul 27, 2023
@jrfnl jrfnl changed the title Class::containsMethod() ObjectDeclarations::getFunctions() Jul 27, 2023
@jrfnl
Copy link
Member

jrfnl commented May 14, 2024

@GaryJones Have a look at #592. I believe that PR addressed this request along the lines of the comment I posted before.

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

Successfully merging a pull request may close this issue.

2 participants