/** * Check all nodes * * @param Node $node * @return void **/ public function enterNode(Node $node) { // Skip nodes without comments. if (!$node->hasAttribute("comments")) { return; } // Check if annotations should be preserved. Only nodes with actual // doc comment blocks are processed. $comments = []; if ($this->preserveAnnotations) { $docComment = $node->getDocComment(); if ($docComment) { $text = $docComment->getText(); // Check if it is a doc comment. if (strpos($text, "/**") !== false) { $text = $this->stripComment($text); if ($text) { $comments = [new Comment($text)]; } } } } // Remove (or set) comments. $node->setAttribute("comments", $comments); return $node; }
/** * Called when entering a node. * * Return value semantics: * * null: $node stays as-is * * otherwise: $node is set to the return value * * @param Node $node Node * * @return null|Node Node */ public function enterNode(Node $node) { if (isset($node->returnType)) { var_dump($node->returnType); die; } elseif ($node instanceof Node\Param) { if ($node->hasAttribute("generic_name")) { $type = $node->getAttribute("generic_name"); if (isset($this->genericTypes[$type])) { $node->type = new Node\Name\FullyQualified($this->genericTypes[$type]); } else { throw new \LogicException("Bad generic found"); } } elseif ($node->type instanceof Node\Name && $node->type->hasAttribute("generics") && $node->type->getAttribute("generics")) { $type = $node->getAttribute("original_type")->parts; foreach ($node->type->getAttribute("generics") as $generic) { if (isset($this->genericTypes[$generic])) { $value = str_replace("\\", Engine::NS_TOKEN, $this->genericTypes[$generic]); $type[] = Engine::CLASS_TOKEN . $value . Engine::CLASS_TOKEN; } else { throw new \LogicException("Bad generic found"); } } $node->type = new Node\Name\FullyQualified($type); } elseif ((string) $node->name == "item") { var_dump($node); die; } } }
public function leaveNode(Node $node) { if ($node->hasAttribute(NameResolver::TAG_NAMES_ATTRIBUTE)) { $tags = $node->getAttribute(NameResolver::TAG_NAMES_ATTRIBUTE); foreach ($tags as $tagName) { $name = new Node\Name($tagName); $name->setAttribute('isComment', true); $this->collect($name, $node); } } }
public function leaveNode(Node $node) { if (!$node->hasAttribute('oldEnabledRules')) { return; } // Restore rules as they were before this node $this->enabledRules = $node->getAttribute('oldEnabledRules'); }
/** * @param \PhpParser\Node $node */ private function detectNowDoc(Node $node) { if ($node->hasAttribute('isNowDoc') && $node instanceof Node\Scalar\String_) { $this->getResult()->addRequirement(Reason::NOWDOC_LITERAL, $node->getLine()); } }
protected function dumpPosition(Node $node) { if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) { return null; } $start = $node->getAttribute('startLine'); $end = $node->getAttribute('endLine'); if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') && null !== $this->code) { $start .= ':' . $this->toColumn($this->code, $node->getAttribute('startFilePos')); $end .= ':' . $this->toColumn($this->code, $node->getAttribute('endFilePos')); } return "[{$start} - {$end}]"; }
private function detectShortEchoSyntax(Node $node) { if ($node instanceof Node\Stmt\Echo_ && $node->hasAttribute('isShortEchoTag')) { $this->getResult()->addRequirement(Reason::SHORT_ECHO_TAG, $node->getLine()); } }
protected function removeGenerics(Node $node) { if (!$node->hasAttribute('generics') || !$node->getAttribute('generics')) { return; } foreach ($node->getAttribute('generics') as $type) { unset($this->currentGenerics[$type]); } }