本文整理汇总了PHP中PhpParser\Node::getLine方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getLine方法的具体用法?PHP Node::getLine怎么用?PHP Node::getLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpParser\Node
的用法示例。
在下文中一共展示了Node::getLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enterNode
function enterNode(\PhpParser\Node $node)
{
if ($node instanceof \PhpParser\Node\Stmt\Namespace_) {
$this->addNamespace(array('namespace' => $node->name->toString(), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Use_) {
foreach ($node->uses as $use) {
$this->addUse(array('name' => $use->name, 'alias' => $use->alias));
}
}
if ($node instanceof \PhpParser\Node\Stmt\Class_) {
$this->addClass(array('name' => $node->name, 'extends' => $node->extends, 'implements' => $node->implements, 'abstract' => $node->isAbstract(), 'final' => $node->isFinal(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Interface_) {
$this->addInterface(array('name' => $node->name, 'extends' => $node->extends, 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\ClassMethod) {
$this->addClassMethod(array('byRef' => $node->byRef, 'name' => $node->name, 'params' => $node->params, 'returnType' => $node->returnType, 'public' => $node->isPublic(), 'protected' => $node->isProtected(), 'private' => $node->isPrivate(), 'abstract' => $node->isAbstract(), 'final' => $node->isFinal(), 'static' => $node->isStatic(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
if ($node instanceof \PhpParser\Node\Stmt\Property) {
$this->last_property = $node;
}
if ($node instanceof \PhpParser\Node\Stmt\PropertyProperty) {
$this->addClassProperty(array('name' => $node->name, 'default' => $node->default, 'public' => $this->last_property->isPublic(), 'protected' => $this->last_property->isProtected(), 'private' => $this->last_property->isPrivate(), 'static' => $this->last_property->isStatic(), 'comment' => $node->getDocComment(), 'doc' => $this->doc_comment_parser->parse($node->getDocComment()), 'line' => $node->getLine(), 'file' => $this->file));
}
// $this->logger->info(get_class($node));
}
示例2: p
protected function p(\PhpParser\Node $node)
{
$prefix = '';
if ($node->getLine() > $this->cur_ln) {
$prefix = str_repeat("\n", $node->getLine() - $this->cur_ln);
$this->cur_ln = $node->getLine();
}
return $prefix . $this->{'p' . $node->getType()}($node);
}
示例3: itShouldCallScanAndWriteOnSuccess
/**
* @test
*/
public function itShouldCallScanAndWriteOnSuccess()
{
$this->node->getLine()->shouldBeCalled()->willReturn(120);
$this->detector->scan($this->node)->shouldBeCalled()->willReturn(true);
$this->detector->isBoolExpression($this->node)->shouldBeCalled()->willReturn(true);
$this->analyser->foundAssumption(120)->shouldBeCalled();
$this->analyser->foundBoolExpression()->shouldBeCalled();
$this->nodeVisitor->enterNode($this->node->reveal());
}
示例4: trace
/**
* @param string $message
*/
public function trace($message, Node $node, $class = null)
{
if ($this->trace === true) {
$this->cleanProgressbar();
$space = 35 - strlen($message);
$spaceAfterMessage = str_repeat(' ', $space <= 1 ? 1 : $space);
$spaceAfterLine = str_repeat(' ', 5 - strlen($node->getLine()));
$this->output->writeln(sprintf('[%s]%s line "%s"%s class "%s"', $message, $spaceAfterMessage, $node->getLine(), $spaceAfterLine, $class));
$this->reDrawProgressBar();
}
}
示例5: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Expr\FuncCall && isset($node->name) && isset($node->name->parts) && ($node->name->parts[0] == '__' || $node->name->parts[0] == '_c') && isset($node->args[0]) && isset($node->args[0]->value->value) && is_string($string = $node->args[0]->value->value)) {
$key = $node->name->parts[0] == '__' ? 2 : 3;
$domain = isset($node->args[$key]) && is_string($node->args[$key]->value->value) ? $node->args[$key]->value->value : 'messages';
$this->results[$domain][$string][] = ['file' => $this->file, 'line' => $node->getLine()];
} elseif ($node instanceof Node\Expr\MethodCall && isset($node->name) && ($node->name == 'trans' || $node->name == 'transChoice') && isset($node->args[0]) && isset($node->args[0]->value->value) && is_string($string = $node->args[0]->value->value)) {
$key = $node->name == 'trans' ? 2 : 3;
$domain = isset($node->args[$key]) && is_string($node->args[$key]->value->value) ? $node->args[$key]->value->value : 'messages';
$this->results[$domain][$string][] = ['file' => $this->file, 'line' => $node->getLine()];
}
}
示例6: leaveNode
/**
* @param Node $node
*
* @return void
*/
public function leaveNode(Node $node)
{
if (!$node instanceof Node\Expr\Exit_) {
return;
}
$this->addError(sprintf('Found a forbidden exit statement.'), $node->getLine(), ParseError::TYPE_ERROR);
}
示例7: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Node $node)
{
// Keep traces of global variable
if ($node instanceof Node\Stmt\Global_) {
foreach ($node->vars as $variable) {
$this->globalsInCurrentLocalScope[] = $variable->name;
}
}
// Check if the variable is marked as global or used in the global scope
if ($node instanceof Node\Expr\Variable) {
if ($this->isInGlobalScope || in_array($node->name, $this->globalsInCurrentLocalScope)) {
$this->checkIfGlobalVariableWasRemoved($node->name, $node->getLine());
}
}
// Check if the variable is used from the $GLOBALS variable
if ($node instanceof Node\Expr\ArrayDimFetch) {
if ($node->var instanceof Node\Expr\Variable && $node->var->name === 'GLOBALS' && $node->dim instanceof Node\Scalar\String_) {
$this->checkIfGlobalVariableWasRemoved($node->dim->value, $node->dim->getLine());
}
}
// Check if we re-enter in the global scope
if ($node instanceof Node\FunctionLike) {
$this->isInGlobalScope = true;
$this->globalsInCurrentLocalScope = array();
}
}
示例8: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Expr\New_ && $node->class instanceof Node\Name) {
$classUsage = new ClassUsage($node->class->toString(), $node->getLine());
$this->phpFileInfo->addClassUsage($classUsage);
}
}
示例9: enterNode
public function enterNode(PhpParser\Node $node)
{
if ($node instanceof Stmt\Function_) {
// create new context, keep parent
$this->stack->start(new FunctionContext($node->name, $node->getLine(), $node->getAttribute('endLine')));
}
}
示例10: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Class_ && $node->extends instanceof Node\Name) {
$superTypeUsage = new SuperTypeUsage($node->extends->toString(), $node->namespacedName->toString(), $node->getLine());
$this->phpFileInfo->addSuperTypeUsage($superTypeUsage);
}
}
示例11: enter
public final function enter(Node $node)
{
switch ($node->getType()) {
case 'Stmt_Namespace':
$this->namespace = $node->name;
$this->aliases = array();
// @todo : with multiple namespaces in one file : does this bug ?
// leave() shouldn't reset these values ?
break;
case 'Stmt_UseUse':
if (isset($this->aliases[$node->alias])) {
throw new \PhpParser\Error(sprintf('Cannot use "%s" as "%s" because the name is already in use', $node->name, $node->alias), $node->getLine());
}
$this->aliases[$node->alias] = $node->name;
break;
case 'Stmt_Class':
$this->context->pushState('class', $node);
$this->enterClassNode($node);
break;
case 'Stmt_Trait':
$this->context->pushState('trait', $node);
$this->enterTraitNode($node);
break;
case 'Stmt_Interface':
$this->context->pushState('interface', $node);
$this->enterInterfaceNode($node);
break;
}
}
示例12: leaveNode
public function leaveNode(Node $node)
{
if ($node instanceof Node\Scalar\String_ || $node instanceof Node\Stmt\InlineHTML) {
$new_data = array('filename' => $this->filename, 'line' => $node->getLine(), 'value' => (string) $node->value);
array_push($this->data, $new_data);
}
}
示例13: leaveNode
/**
* {@inheritdoc}
*/
public function leaveNode(Node $node)
{
if ($node instanceof Stmt\Class_ || $node instanceof Stmt\Interface_ || $node instanceof Stmt\Trait_) {
$this->check($node->name, $node->getLine(), '"%s" is now a reserved type and can no longer be used as the name of a class/interface/trait.');
} elseif ($node instanceof Stmt\Use_ && $node->type === Stmt\Use_::TYPE_NORMAL) {
$this->check($node->uses[0]->alias, $node->getLine(), '"%s" is now a reserved type and can no longer be used as an alias.');
} elseif ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && $node->name->parts === array('class_alias')) {
$args = $node->args;
if (!empty($args[1]) && $args[1]->value instanceof Node\Scalar\String_) {
$fqcn = $args[1]->value->value;
$parts = explode('\\', $fqcn);
$className = end($parts);
$this->check($className, $node->getLine(), '"%s" is now a reserved type and can no longer be used in class_alias().');
}
}
}
示例14: leaveNode
/**
* @link http://www.slideshare.net/rdohms/your-code-sucks-lets-fix-it-15471808
* @link http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php
*
* @param Node $node
*
* @return void
*/
public function leaveNode(Node $node)
{
if (!$node instanceof Node\Stmt\Else_ && !$node instanceof Node\Stmt\ElseIf_) {
return;
}
$this->addError(sprintf('Object Calisthenics error: Do not use the "%s" keyword!', $node instanceof Node\Stmt\ElseIf_ ? 'elseif' : 'else'), $node->getLine(), ParseError::TYPE_ERROR);
}
示例15: enterNode
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\ClassLike) {
if (isset($node->namespacedName)) {
$this->parentName = $node->namespacedName->toString();
} else {
$this->parentName = $node->name;
}
}
if ($node instanceof Node\Expr\MethodCall) {
// skips concat method names like $twig->{'get'.ucfirst($type)}()
if ($node->name instanceof Node\Expr\BinaryOp\Concat) {
return;
}
// skips variable methods like $definition->$method
if (!is_string($node->name)) {
return;
}
$type = $node->var->getAttribute('guessedType', null);
if (null !== $type) {
$methodUsage = new MethodUsage($node->name, $type, $node->getLine(), false);
$this->phpFileInfo->addMethodUsage($methodUsage);
}
}
}