当前位置: 首页>>代码示例>>PHP>>正文


PHP Node::getAttribute方法代码示例

本文整理汇总了PHP中PhpParser\Node::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getAttribute方法的具体用法?PHP Node::getAttribute怎么用?PHP Node::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhpParser\Node的用法示例。


在下文中一共展示了Node::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: enterNode

 /**
  * 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;
         }
     }
 }
开发者ID:killer100,项目名称:PhpGenerics,代码行数:41,代码来源:Generator.php

示例2: enterNode

 public function enterNode(AstNode $node)
 {
     // Determine information about the closure's location
     if (!$this->closureNode) {
         if ($node instanceof NamespaceNode) {
             $namespace = $node->name && is_array($node->name->parts) ? implode('\\', $node->name->parts) : null;
             $this->location['namespace'] = $namespace;
         }
         if ($node instanceof TraitNode) {
             $this->location['trait'] = $node->name;
             $this->location['class'] = null;
         } elseif ($node instanceof ClassNode) {
             $this->location['class'] = $node->name;
             $this->location['trait'] = null;
         }
     }
     // Locate the node of the closure
     if ($node instanceof ClosureNode) {
         if ($node->getAttribute('startLine') == $this->location['line']) {
             if ($this->closureNode) {
                 $line = $this->location['file'] . ':' . $node->getAttribute('startLine');
                 throw new ClosureAnalysisException("Two closures were " . "declared on the same line ({$line}) of code. Cannot " . "determine which closure was the intended target.");
             } else {
                 $this->closureNode = $node;
             }
         }
     }
 }
开发者ID:cruni505,项目名称:prestomed,代码行数:28,代码来源:ClosureLocatorVisitor.php

示例3: isTooLong

 /**
  * Checks if a function, class or method is too long according to its lines of code
  *
  * @param Node $node
  * @param int $threshold
  * @return bool
  */
 protected function isTooLong(Node $node, $threshold)
 {
     $startLine = $node->getAttribute('startLine');
     $endLine = $node->getAttribute('endLine');
     $loc = $endLine - $startLine;
     return $loc > $threshold;
 }
开发者ID:kabirbaidhya,项目名称:Inspector,代码行数:14,代码来源:LinesOfCodeChecker.php

示例4: leaveNode

 public function leaveNode(\PhpParser\Node $node)
 {
     if (($parentFile = $this->getCurrentFile()) !== null) {
         if ($node instanceof \PhpParser\Node\Expr\Include_) {
             $currentFile = self::getIncludeFile($node->expr, ['__DIR__' => dirname($parentFile), '__FILE__' => $parentFile]);
             if ($node->type == \PhpParser\Node\Expr\Include_::TYPE_INCLUDE_ONCE || $node->type == \PhpParser\Node\Expr\Include_::TYPE_REQUIRE_ONCE) {
                 if ($this->getPhpFileCombine()->isParsed($currentFile)) {
                     return \PhpParser\NodeTraverser::REMOVE_NODE;
                 }
             }
             if ($this->getPhpFileCombine()->parseFile($currentFile, $parentFile) === false) {
                 return \PhpParser\NodeTraverser::REMOVE_NODE;
             }
             $stmts = $this->getPhpFileCombine()->traverseIncludeNodes()->getStmts();
             if (isset($stmts[0])) {
                 if ($stmts[0] instanceof \PhpParser\Node\Stmt\Namespace_ === false) {
                     $stmts[0]->setAttribute('comments', array_merge($node->getAttribute('comments', []), $stmts[0]->getAttribute('comments', [])));
                 } else {
                     $stmts[0]->stmts[0]->setAttribute('comments', array_merge($node->getAttribute('comments', []), $stmts[0]->stmts[0]->getAttribute('comments', [])));
                 }
             }
             return $stmts;
         }
     }
 }
开发者ID:cakebake,项目名称:php-sources-combiner,代码行数:25,代码来源:IncludeNodeVisitor.php

示例5: __construct

 public function __construct($message, AbstractRule $rule, Node $node, $file)
 {
     $this->message = $message;
     $this->rule = $rule;
     $this->file = $file;
     $this->startLine = $node->getAttribute('startLine');
     $this->endLine = $node->getAttribute('endLine');
 }
开发者ID:stefk,项目名称:md,代码行数:8,代码来源:Violation.php

示例6: getLineNumber

 /**
  * Get the line number of the error.
  *
  * @return string
  */
 public function getLineNumber()
 {
     $sl = $this->node->getAttribute('startLine');
     $el = $this->node->getAttribute('endLine');
     if ($sl != $el) {
         return "{$sl}-{$el}";
     } else {
         return (string) $sl;
     }
 }
开发者ID:anlutro,项目名称:phint,代码行数:15,代码来源:Error.php

示例7: enterNode

 public function enterNode(Node $node)
 {
     if ($node instanceof Node\Expr\Yield_) {
         $startTokenPosition = $node->getAttribute('startTokenPos');
         $endTokenPosition = $node->getAttribute('endTokenPos');
         if (!($this->tokenCollection->isTokenPrecededBy($startTokenPosition, '(') && $this->tokenCollection->isTokenFollowedBy($endTokenPosition, ')')) && !$this->expressionStack->isEmpty()) {
             $this->addContextMessage('"yield" usage in expression context', $this->expressionStack->top());
         }
     } elseif ($node instanceof Node\Expr) {
         $this->expressionStack->push($node);
     }
 }
开发者ID:lzpfmh,项目名称:php7cc,代码行数:12,代码来源:YieldInExpressionContextVisitor.php

示例8: enterNode

 public function enterNode(Node $node)
 {
     if (empty($this->node) && $this->line == $node->getAttribute('endLine')) {
         $this->node = $node;
     }
     parent::enterNode($node);
 }
开发者ID:angrybender,项目名称:phpPM,代码行数:7,代码来源:NodeVisitor.php

示例9: leaveNode

 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;
     }
 }
开发者ID:sibenye,项目名称:naijaskillhub,代码行数:26,代码来源:NodeVisitor.php

示例10: 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')));
     }
 }
开发者ID:edsonmedina,项目名称:php_testability,代码行数:7,代码来源:GlobalFunctionVisitor.php

示例11: resolveVariableType

 /**
  * @inheritDoc
  */
 public function resolveVariableType(Node $node)
 {
     // $this->call()
     if ($node instanceof Node\Expr\MethodCall && property_exists($node->var, 'name') && null === $node->getAttribute('guessedType', null)) {
         if ('container' == $node->var->name && $this->isController($this->table->lookUp('this')->type())) {
             $context = self::CONTAINER;
         } else {
             $context = $this->table->lookUp($node->var->name)->type();
         }
         $type = $this->getType($context, $node->name, $node);
         if (null !== $type) {
             $node->setAttribute('guessedType', $type);
         }
     }
     // $x = $this->call()
     if ($node instanceof Node\Expr\Assign && $node->var instanceof Node\Expr\Variable && $node->expr instanceof Node\Expr\MethodCall && property_exists($node->expr->var, 'name') && null === $node->getAttribute('guessedType', null)) {
         if ('container' == $node->expr->var->name && $this->isController($this->table->lookUp('this')->type())) {
             $context = self::CONTAINER;
         } else {
             $context = $this->table->lookUp($node->expr->var->name)->type();
         }
         $type = $this->getType($context, $node->expr->name, $node->expr);
         if (null !== $type) {
             $node->var->setAttribute('guessedType', $type);
             $this->table->setSymbol($node->var->name, $type);
         }
     }
 }
开发者ID:rnuernberg,项目名称:deprecation-detector,代码行数:31,代码来源:SymfonyResolver.php

示例12: enterNode

 public function enterNode(Node $node)
 {
     if (!$node instanceof Exit_) {
         return;
     }
     $name = $node->getAttribute('kind') === Exit_::KIND_EXIT ? 'exit' : 'die';
     $this->reporter->addViolation("Found {$name}() call", $this, $node);
 }
开发者ID:stefk,项目名称:md,代码行数:8,代码来源:ExitExpression.php

示例13: leaveNode

 public function leaveNode(Node $node)
 {
     if (!$node instanceof ClassMethod) {
         return;
     }
     $pos = $node->getAttribute('startTokenPos');
     MethodPatcher::$replacement[$pos] = true;
 }
开发者ID:ricpelo,项目名称:codeigniter-heroku,代码行数:8,代码来源:NodeVisitor.php

示例14: getCommentsText

 private function getCommentsText(Node $node)
 {
     $text = '';
     $comments = $node->getAttribute('comments');
     foreach ($comments as $comment) {
         $text .= $comment->getReformattedText();
     }
     return $text;
 }
开发者ID:sourcegraph,项目名称:srclib-php,代码行数:9,代码来源:DocExtractor.php

示例15: enterNode

 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if ($node instanceof Node\Scalar\LNumber) {
         $originalValue = $node->getAttribute('originalValue');
         if ($originalValue && $this->isInvalidOctalLiteral($originalValue)) {
             $this->errorCollection->add(new Error($this->parserContext->getFilename(), $node->getLine(), sprintf('"%s" is an invalid octal literal and will now triggers a parse error.', $originalValue)));
         }
     }
 }
开发者ID:jolicode,项目名称:php7-checker,代码行数:12,代码来源:IntegerHandlingChangedChecker.php


注:本文中的PhpParser\Node::getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。