/** * 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; }
public function enterNode(Node $node) { if (!empty($this->stack)) { $node->setAttribute('parent', $this->stack[count($this->stack) - 1]); } $this->stack[] = $node; }
public function leaveNode(Node $node) { if ($node instanceof Node\Expr\Assign && $node->var instanceof Node\Expr\Variable && $this->var == $node->var->name) { $this->var = null; } elseif (!is_null($this->var) && ($node instanceof Node\Expr\FuncCall || $node instanceof Node\Expr\MethodCall || $node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\Closure)) { $node->setAttribute('in_var', $this->var); return $node; } }
public function enterNode(Node $node) { $node->setAttribute('scope', implode(self::SCOPE_SEPARATOR, $this->scope)); if ($node instanceof Node\Stmt\NameSpace_ || $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Stmt\Function_) { $this->scope[] = $node->name; } elseif ($node instanceof Node\Expr\Closure) { $this->scope[] = self::CLOSURE_NAME; } return $node; }
/** * {@inheritdoc} */ public function resolveVariableType(Node $node) { if ($node instanceof Node\Expr\PropertyFetch) { // $this->someProperty if ($node->var instanceof Node\Expr\Variable && $node->var->name === 'this') { $node->setAttribute('guessedType', $this->table->lookUpClassProperty($node->name)->type()); } // $x->someProperty } }
public function enterNode(Node $node) { $node->setAttribute("scope", end($this->scope)); if ($node instanceof Stmt\Namespace_ and !empty($node->name)) { $this->namespace = new NamespaceName($node->name->parts); $this->scope[] = new Scope\NamespaceScope($this->namespace); } elseif ($node instanceof Stmt\Class_) { $this->scope[] = new Scope\ClassScope($this->namespace, $node->name); } elseif ($node instanceof Stmt\Function_) { $this->scope[] = new Scope\FunctionScope($this->namespace, $node->name); } elseif ($node instanceof Stmt\ClassMethod) { $this->scope[] = new Scope\ClassMethodScope(end($this->scope), $node->name); } elseif ($node instanceof Expr\Closure) { $identifier = $node->getAttribute("startFilePos", mt_rand()); $node->setAttribute("identifier", $identifier); // The Closure node now has identifier for common use $this->scope[] = new Scope\ClosureScope(end($this->scope), $identifier); } $node->setAttribute("scopeInner", end($this->scope)); }
public function enterNode(Node $node) { $node->setAttribute("scope", end($this->scope)); if ($node instanceof Stmt\Namespace_ and !empty($node->name)) { $this->namespace = new NamespaceName($node->name->parts); } elseif ($node instanceof Stmt\Class_) { $this->scope[] = new Scope\ClassScope($this->namespace, $node->name); } elseif ($node instanceof Stmt\Function_) { $this->scope[] = new Scope\FunctionScope($this->namespace, $node->name); } elseif ($node instanceof Stmt\ClassMethod) { $this->scope[] = new Scope\ClassMethodScope(end($this->scope), $node->name); } elseif ($node instanceof Expr\Closure) { $this->scope[] = new Scope\ClosureScope(end($this->scope), $node->getAttribute("startFilePos", mt_rand())); } }
/** * {@inheritdoc} */ public function resolveVariableType(Node $node) { if ($node instanceof Node\Expr\Variable) { $node->setAttribute('guessedType', $this->table->lookUp($node->name)->type()); } }
/** * Compute the version of an internal function. * * @param Node $node * @param string $element * @param string $context * * @return void */ private function computeInternalVersions(Node $node, $element, $context, $extra = null) { $versions = $node->getAttribute('compatinfo'); if ($versions === null) { // find reference info $argc = isset($node->args) ? count($node->args) : 0; $versions = $this->references->find($context, $element, $argc, $extra); $versions['ext.all'] = $versions['php.all'] = ''; if ($argc) { foreach ($node->args as $arg) { if ($arg->value instanceof Node\Expr\BinaryOp\Pow) { // Exponentiation $this->updateVersion('5.6.0', $versions['php.min']); } } } // cache to speed-up later uses $node->setAttribute('compatinfo', $versions); } $node->setAttribute('fileName', $this->file); if ('methods' == $context) { $element = sprintf('%s::%s', $extra, $element); } // update versions of $element $this->updateElementVersion($context, $element, $versions); ++$this->metrics[$context][$element]['matches']; // update local context $this->updateLocalVersions($versions, isset($this->metrics[$context][$element]['optional'])); }
protected function transform(Node $node) { $node->type = null; $node->setAttribute('changed', true); return $node; }
/** * Perform action * * @param Node $node * @return void|bool Void if node should remain, false if not */ public function leaveNode(Node $node) { $node->setAttribute('comments', []); }
protected function transform(Node $node) { $node->name = '__construct'; $node->setAttribute('changed', true); return $node; }