本文整理汇总了PHP中PhpParser\Node::getParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getParams方法的具体用法?PHP Node::getParams怎么用?PHP Node::getParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::getParams方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recordFunctionParameterTypesUsage
private function recordFunctionParameterTypesUsage(Node $node)
{
if ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) {
foreach ($node->getParams() as $param) {
if ($param->type instanceof Node\Name) {
$this->recordUsageOf($param->type);
}
if (is_string($param->type)) {
$this->recordUsageOfByString($param->type);
}
}
}
}
示例2: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if (!$node instanceof Node\FunctionLike) {
return;
}
$parametersNames = array();
foreach ($node->getParams() as $parameter) {
$currentParameterName = $parameter->name;
if (!isset($parametersNames[$currentParameterName])) {
$parametersNames[$currentParameterName] = false;
} elseif (!$parametersNames[$currentParameterName]) {
$this->addContextMessage(sprintf('Duplicate function parameter name "%s"', $currentParameterName), $node);
$parametersNames[$currentParameterName] = true;
}
}
}
示例3: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Node $node)
{
if ($node instanceof Node\FunctionLike) {
$params = $node->getParams();
$paramNames = array();
$hasParameterWithSameName = false;
array_walk($params, function (Node\Param $param) use(&$paramNames, &$hasParameterWithSameName) {
if (array_key_exists($param->name, $paramNames)) {
$hasParameterWithSameName = true;
}
$paramNames[$param->name] = true;
});
if ($hasParameterWithSameName) {
$this->errorCollection->add(new Error($this->parserContext->getFilename(), $node->getLine(), 'Functions can no longer have more than one parameter with the same name.'));
}
}
}
示例4: enterNode
/**
* @inheritdoc
* @param \PhpParser\Node $node
* @return null|\PhpParser\Node|void
*/
public function enterNode(Node $node)
{
// direct class calls
if ($node instanceof Node\Expr\New_ || $node instanceof Node\Expr\StaticCall || $node instanceof Node\Expr\ClassConstFetch || $node instanceof Node\Expr\StaticPropertyFetch) {
if ($node->class instanceof Node\Name) {
$this->handleClassName($node->class);
}
if ($node instanceof Node\Expr\ClassConstFetch) {
$this->handleConstantName($node->name, $node->getLine());
}
} elseif ($node instanceof Node\FunctionLike) {
if (!empty($node->getParams())) {
foreach ($node->getParams() as $param) {
if (isset($param->type) && !is_string($param->type)) {
$this->handleClassName($param->type);
}
}
}
} elseif ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Interface_) {
$names = [];
if (!empty($node->implements)) {
$names += $node->implements;
}
if (!empty($node->extends)) {
if ($node->extends instanceof Name) {
$names[] = $node->extends;
} else {
$names += $node->extends;
}
}
foreach ($names as $name) {
$this->handleClassName($name);
}
} elseif ($node instanceof Node\Expr\FuncCall && !$node->name instanceof Node\Expr) {
$this->handleFunctionName($node->name);
} elseif ($node instanceof Node\Expr\ConstFetch) {
$this->handleConstantName($node->name);
}
}
示例5: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Namespace_) {
$this->aliases = [];
return;
}
if ($node instanceof Node\Stmt\Use_) {
foreach ($node->uses as $use) {
$this->aliases[$use->alias] = (string) $use->name;
}
return;
}
if ($node instanceof Node\Stmt\ClassMethod) {
$params = $node->getParams();
if (!count($params)) {
return;
}
$param1 = $params[0];
$paramClass = $this->resolveAlias((string) $param1->type);
if (is_subclass_of($paramClass, '\\Symfony\\Component\\Validator\\Context\\ExecutionContextInterface')) {
$this->contextVariable = $param1->name;
}
return;
}
if ($node instanceof Node\Expr\MethodCall) {
$this->parseMethodCall($node);
}
}