/** * @param Node\Stmt\Class_ $node */ protected function parseClassNode(Node\Stmt\Class_ $node) { if (!isset($node->namespacedName)) { return; // Ticket #45 - This could potentially not be set for PHP 7 anonymous classes. } $this->currentStructuralElement = $node; $interfaces = []; /** @var Node\Name $implementedName */ foreach ($node->implements as $implementedName) { $interfaces[] = $implementedName->toString(); } $this->structuralElements[$node->namespacedName->toString()] = ['name' => $node->name, 'type' => 'class', 'startLine' => $node->getLine(), 'isAbstract' => $node->isAbstract(), 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null, 'parents' => $node->extends ? [$node->extends->toString()] : [], 'interfaces' => $interfaces, 'traits' => [], 'methods' => [], 'properties' => [], 'constants' => []]; }
/** * Gets a single class generated by the template. * * @param Class_ $statement * @param string $namespace * @param string $fileLocation * @param string $uses * @returns string $code */ protected function getClass(Class_ $statement, $namespace, $fileLocation, $uses = '') { $comments = $statement->getDocComment(); $comments = isset($comments) ? $comments->getText() : ''; if ($namespace == 'tmp') { $namespace = ''; } else { $namespace = 'namespace ' . $namespace . ';'; } $event = new GetClassEvent($statement, $fileLocation, $namespace, $uses); $this->dispatcher->dispatch(GetClassEvent::BEFORE, $event); $namespace = $event->getNamespace(); $uses = $event->getUses(); $statement = $event->getStatements(); $code = $this->prettyPrinter->pStmt_Class($statement); if (isset($this->template)) { $code = call_user_func($this->template, $namespace, $uses, $comments, $code); } $event->setCode($code); $this->dispatcher->dispatch(GetClassEvent::AFTER, $event); $code = $event->getCode(); return $code; }