How to add use statements to a class #7529
Unanswered
alexander-schranz
asked this question in
Q&A
Replies: 1 comment
-
Let's keep it one place to avoid loosing focus :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to add use statements inside a rector rule. I parsed the class, added some modifcation to it which are correctly applied. The last part I'm lost is adding the required
use
statements.I'm loading the namespace via:
Check via
$namespace->stmts
if any the classes I want to add are already there. For all classes not already there I use:It seems like array_unshift seems to be the correct way to add something here. But I could also not found any method adding a namespace. I searched for any usage of
$this->nodeFactory->createUsesFromNames
in rector itself but could not answer it.The whole rule can be found here: https://github.com/rectorphp/rector-phpunit/pull/114/files#diff-2078d04046a7473b060d6040ceb1159e0f41d36ecb12063a91ad6267bb8c7086R177-R179
Beta Was this translation helpful? Give feedback.
All reactions