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
POC for the new php_blacklist task #108
Conversation
Exemple with YAML config parameters:
bin_dir: "./vendor/bin"
git_dir: "/var/grumphp/examples"
tasks:
php_blacklist:
keywords:
- "::var_export("
- "var_dump("
- "->print_r("
- "error_log(" Searching for |
Thanks for the PR. I will take a deeper look at it as soon as possible! |
I know the problem with Travis job and I've check in. Issue come from PHP_CodeSniffer (version used 2.3.0). Ok for other task todo (unit tests, ...) but I can do it only this week end now |
Hi @llaville, It looks pretty nice already, but I think there are some things we can improve GrumPHP\Task\ParseErrorsCollection
GrumPHP\Task\Php\Blacklist
GrumPHP\Task\AbstractParserTask
GrumPHP\Parser\ParserInterface
GrumPHP\Parser\Php\NodeVisitor
GrumPHP\Parser\Php\PhpParser
TODO: Testing + documentation. You really did a great job on this PR already, really appreciate it! Thanks! |
Hi @veewee, I really appreciate your deeply code review :) I'll try to fix all points, but it should be propably for monday or tuesday now ! Thanks. |
No problem! Take your time :) |
…ified for this blacklist task
…se the short name in the docblocks
I've already fixed some point, but I'm still working on other improvements. Especially the node visitors option registered as services. |
@veewee About your comment
I've just implemented a solution, but I'm not sure it is that you've in mind Current config will be:
If option I've create a new node visitor (e.g) to check class constant |
Well I was thinking about splitting the visitors up into separate visitors:
Those visitors can be added as services in the container. Something like: services:
grumphp.parser.php.visitor.function_call:
class: GrumPHP\Parser\Php\Visitor\FunctionCallVisitor
tags: {name: php_parser.visitor}
public: false
parameters:
php_blacklist:
keywords:
- "::var_export("
- "var_dump("
- "->print_r("
- "error_log("
- "BAR"
visitors:
- '@grumphp.parser.php.visitor.function_call' This would require an additional collection class which contains a full list of all visitors on which it is possible to filter based on the configured visitors. |
ok thanks for feedback. I'll review my code copy ! |
I must admit, I've some difficulties to retrieve list of services corresponding to node visitors. I've checked on ContainerFactory and two compilers examples, but no way to add a new one (an idea ?). So how to get list of node visitors services ? Help would be greatly appreciated. Thanks in advance. |
Probably via a new extension that is the only way we can configure it ? |
Hello @llaville, We don't need an extension for this. So basically you can add a visitor service and tag is as a php.parser.visitor or something like that. The CompilerPass will load all the tagged visitors and append them to the php parser. When running the parser, the registered visitors are filtered by the configured parser options. I am leaving on vacation today, but will be back in one week if you need additional help. Maybe someone else can help out in the meantime. (/cc @aderuwe? ) |
Ok finally it was as I've expected first. BTW, and in parallel I've worked on a copy that used visitors as class name strings. |
With such config php_blacklist:
keywords:
- "::var_export("
- "var_dump("
- "->print_r("
- "->run("
- "error_log("
- "BAR"
visitors:
- 'GrumPHP\Parser\Php\Visitor\FunctionCallVisitor'
- 'GrumPHP\Parser\Php\Visitor\ConcreteMethodCallVisitor'
- 'GrumPHP\Parser\Php\Visitor\StaticMethodCallVisitor' Visitors are registered as string class names (not yet services: WIP), I've results expected.
Last line is produced by PHP_Parser that act as a |
Just added visitors as services implementation. See commit 7e6936f
|
Thanks for the work! I will try to take the time to review your code at the end of the week. |
Ok waiting for your feedback that have a great importance for me ! |
Hi @llaville, Sorry it took me so long, but I didn't find the time this weekend.
What do you think about this way of configuring? Do you think it's possible? This will enable people to create their own kick-ass visitors. Looks pretty cool to me.
|
Hi @llaville, It's been a while since your last worked on this PR. We are assembling features for our next 0.9.0 relase and I was wondering if you needed some additional help with this PR? |
@veewee Sorry I've been busy at Office, and have not enough free time to work on this subject. |
@veewee I've just pushed new PR #138 related to code changes
parameters:
tasks:
php_parser:
visitors_options:
function_call_visitor:
blacklist: ["var_dump", "error_log"]
whitelist: ["count", "get_class"]
concrete_method_call_visitor:
blacklist: ["print_r", "run"]
static_method_call_visitor:
blacklist: ["var_export"]
visitors:
- {visitor: '@grumphp.parser.php.visitor.function_call'}
- {visitor: '@grumphp.parser.php.visitor.concrete_method_call'}
- {visitor: '@grumphp.parser.php.visitor.static_method_call'}
triggered_by: [php]
ignore_patterns: [] |
This PR is being continued in #138. |
A draft version to solve situation presented in #53 with the PHP_Parser rather than with php tokens.