/** * Utility method to PSR4-ify a class. It'll move the class into its own file * in the given module's namespace. The class is modified in-place, so you * should clone it before calling this function if you want to make a PSR-4 * *copy* of it. * * @param \Drupal\drupalmoduleupgrader\TargetInterface $target * The module which will own the class. * @param \Pharborist\ClassNode $class * The class to modify. * * @return \Pharborist\ClassNode * The modified class, returned for convenience. */ public static function toPSR4(TargetInterface $target, ClassNode $class) { $ns = 'Drupal\\' . $target->id(); RootNode::create($ns)->getNamespace($ns)->append($class->remove()); WhitespaceNode::create("\n\n")->insertBefore($class); return $class; }
public function move(ClassNode $test) { $ns = 'Drupal\\' . $this->target->id() . '\\Tests'; RootNode::create($ns)->getNamespace($ns)->append($test->remove()); WhitespaceNode::create("\n\n")->insertBefore($test); $this->writeClass($this->target, $test); }