How to add a namespace
to a class if non is set?
#8290
Answered
by
samsonasik
numediaweb
asked this question in
Q&A
-
QuestionI have been playing with this nice library: good job by the way 👏 Trying to create my own custom rule that adds a The file I have:<?php
class MyClass extends SecureControllerAction {
...
} The results I expect:<?php
namespace App\Controller;
class MyClass extends SecureControllerAction {
...
} My current rule /**
* @return string[]
*/
public function getNodeTypes(): array
{
return [
Name::class,
Class_::class,
Namespace_::class,
];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node): ?Node
{
// Here I'am stuck as the file itself doesn't have a namespace node!
} Any help would be appreciated 🙏 |
Beta Was this translation helpful? Give feedback.
Answered by
samsonasik
Jan 21, 2024
Replies: 2 comments 1 reply
-
You can use |
Beta Was this translation helpful? Give feedback.
1 reply
-
@numediaweb FYI, this feature is removed, Rector is now only rename class reference, not class name, see:
for the reasoning |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
samsonasik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@numediaweb FYI, this feature is removed, Rector is now only rename class reference, not class name, see:
for the reasoning