Example #1
0
 /**
  * Determine if the node belongs to this namespace.
  *
  * @param ClassNode|InterfaceNode|TraitNode|FunctionDeclarationNode|ConstantDeclarationNode $node
  *   Node to test if owned by namespace.
  *
  * @return bool
  */
 public function owns($node)
 {
     return $this === $node->getName()->getNamespace();
 }
 /**
  * Writes a class to the target module's PSR-4 root.
  *
  * @param TargetInterface $target
  *  The target module.
  * @param ClassNode $class
  *  The class to write. The path will be determined from the class'
  *  fully qualified name.
  *
  * @return string
  *  The generated path to the class.
  */
 public function writeClass(TargetInterface $target, ClassNode $class)
 {
     $class_path = ltrim($class->getName()->getAbsolutePath(), '\\');
     $path = str_replace(['Drupal\\' . $target->id(), '\\'], ['src', '/'], $class_path) . '.php';
     return $this->write($target, $path, $class->parents()->get(0));
 }