How to add a namespace
to a class if non is set?
#8290
-
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.
Replies: 2 comments 1 reply
-
You can use |
Beta Was this translation helpful? Give feedback.
-
@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.
@numediaweb FYI, this feature is removed, Rector is now only rename class reference, not class name, see:
for the reasoning