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

Functions::containsToken() #126

Open
GaryJones opened this issue Mar 29, 2020 · 4 comments
Open

Functions::containsToken() #126

GaryJones opened this issue Mar 29, 2020 · 4 comments

Comments

@GaryJones
Copy link
Contributor

Idea: have a way to see if a function contains a particular token, or some combination of tokens:

Functions::containsToken( `$function_name`, $token );
// or
Functions::containsToken( $stackPtr, $token );

Perhaps could also handle the logic for Class::methodContainsToken() or similar as well.

@jrfnl
Copy link
Member

jrfnl commented Mar 29, 2020

Would this be for the function the original $stackPtr was found in ? Or another function in the same file ?

@GaryJones
Copy link
Contributor Author

Specific use case is trying to determine if a filter callback contains T_RETURN or not.

With sensible guard clauses to reduce the amount of time this had to run, I'd expect any Functions::containsToken() call to find the function opener and closer for $function_name, and look at each of the tokens in between to see if matches $token.

It would allow sniff-writers to be less concerned with finding and looping through opener and closer tokens, and be able to ask "Does this function contain a return [token]?"

For a combination of tokens, $token might be an array, and the lookup would allow for T_WHITESPACE in between or something (less of an concrete idea about this bit at the moment).

@jrfnl
Copy link
Member

jrfnl commented Mar 29, 2020

See my side-note about this here: #122 (comment)

@GaryJones
Copy link
Contributor Author

something like Method::containsToken( [ 'Foo', 'bar' ], T_RETURN ); would still not be reliable as the method may not contain a T_RETURN for all exit paths in the method or could contain a nested closure which has a return, but the function itself does not.

At least for the second one, perhaps the Functions::containsToken() should consider excluding tokens not in the the immediate function scope?

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

No branches or pull requests

2 participants