public function leaveNode(Node $node) { if (!$node instanceof ConstFetch) { $callback = [$this, 'rewrite' . ucfirst($node->getType())]; if (is_callable($callback)) { call_user_func_array($callback, [$node]); } return; } if ($this->disable_const_rewrite_level > 0) { return; } if (!$node->name instanceof Name) { return; } if (!$node->name->isUnqualified()) { return; } if (!ConstantPatcher::isBlacklisted((string) $node->name)) { $replacement = new FullyQualified(array()); $replacement->set('\\__ConstProxy__::get(\'' . (string) $node->name . '\')'); $pos = $node->getAttribute('startTokenPos'); ConstantPatcher::$replacement[$pos] = '\\__ConstProxy__::get(\'' . (string) $node->name . '\')'; $node->name = $replacement; } }
public function leaveNode(PhpParser\Node $node) { if (!$node instanceof FuncCall) { return; } if (!$node->name instanceof Name) { return; } if ($node->name->isUnqualified() && !CIPHPUnitTestFunctionPatcher::isBlacklisted((string) $node->name)) { $replacement = new FullyQualified(array()); $replacement->set('CIPHPUnitTestFunctionPatcherProxy::' . (string) $node->name); $pos = $node->getAttribute('startTokenPos'); CIPHPUnitTestFunctionPatcher::$replacement[$pos] = '\\CIPHPUnitTestFunctionPatcherProxy::' . (string) $node->name; $node->name = $replacement; } }
public function leaveNode(Node $node) { if (!$node instanceof FuncCall) { return; } if (!$node->name instanceof Name) { return; } if (!$node->name->isUnqualified()) { return; } if (FunctionPatcher::isWhitelisted((string) $node->name) && !FunctionPatcher::isBlacklisted((string) $node->name)) { $replacement = new FullyQualified(array()); $replacement->set('\\__FuncProxy__::' . (string) $node->name); $pos = $node->getAttribute('startTokenPos'); FunctionPatcher::$replacement[$pos] = '\\__FuncProxy__::' . (string) $node->name; $node->name = $replacement; } }
protected function resolveOtherName(Name $name, $type) { // fully qualified names are already resolved if ($name->isFullyQualified()) { return $name; } // resolve aliases for qualified names $aliasName = strtolower($name->getFirst()); if ($name->isQualified() && isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName])) { $alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName]; return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes()); } if ($name->isUnqualified()) { if ($type === Stmt\Use_::TYPE_CONSTANT) { // constant aliases are case-sensitive, function aliases case-insensitive $aliasName = $name->getFirst(); } if (!isset($this->aliases[$type][$aliasName])) { // unqualified, unaliased names cannot be resolved at compile-time return $name; } // resolve unqualified aliases return new FullyQualified($this->aliases[$type][$aliasName], $name->getAttributes()); } if (null !== $this->namespace) { // if no alias exists prepend current namespace return FullyQualified::concat($this->namespace, $name, $name->getAttributes()); } return new FullyQualified($name->parts, $name->getAttributes()); }
protected function extractNameFullyQualified(Name\FullyQualified $node) { return ['DefPath' => $node->toString('/')]; }
protected function resolveOtherName(Name $name, $type) { if ($this->preserveOriginalNames) { // Save the original name $originalName = $name; $name = clone $originalName; $name->setAttribute('originalName', $originalName); } // fully qualified names are already resolved if ($name->isFullyQualified()) { return $name; } // resolve aliases for qualified names $aliasName = strtolower($name->getFirst()); if ($name->isQualified() && isset($this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName])) { $alias = $this->aliases[Stmt\Use_::TYPE_NORMAL][$aliasName]; return FullyQualified::concat($alias, $name->slice(1), $name->getAttributes()); } if ($name->isUnqualified()) { if ($type === Stmt\Use_::TYPE_CONSTANT) { // constant aliases are case-sensitive, function aliases case-insensitive $aliasName = $name->getFirst(); } if (isset($this->aliases[$type][$aliasName])) { // resolve unqualified aliases return new FullyQualified($this->aliases[$type][$aliasName], $name->getAttributes()); } if (null === $this->namespace) { // outside of a namespace unaliased unqualified is same as fully qualified return new FullyQualified($name, $name->getAttributes()); } // unqualified names inside a namespace cannot be resolved at compile-time // add the namespaced version of the name as an attribute $name->setAttribute('namespacedName', FullyQualified::concat($this->namespace, $name, $name->getAttributes())); return $name; } // if no alias exists prepend current namespace return FullyQualified::concat($this->namespace, $name, $name->getAttributes()); }