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


PHP PhpParser\Node类代码示例

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


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

示例1: 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);
 }
开发者ID:phpro,项目名称:grumphp,代码行数:15,代码来源:NeverUseElseVisitor.php

示例2: enterNode

 /**
  * {@inheritdoc}
  */
 public function enterNode(Node $node)
 {
     if ($node instanceof Node\Param && $node->type instanceof Node\Name) {
         $typeHintUsage = new TypeHintUsage($node->type->toString(), $node->getLine());
         $this->phpFileInfo->addTypeHintUsage($typeHintUsage);
     }
 }
开发者ID:slde-thespirit,项目名称:deprecation-detector,代码行数:10,代码来源:FindArguments.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: push

 /**
  * @param Node|string|array|\Traversable|array $symbol
  * @return Node|string|array|\Traversable|array
  */
 public function push($symbol)
 {
     if ($symbol === false || $symbol === null || $symbol === '') {
         return $symbol;
     }
     if ($symbol instanceof Buffer) {
         $this->push($symbol->toValue());
     } elseif ($symbol instanceof Node) {
         $this->parts[] = $symbol;
         $this->length++;
     } elseif (is_string($symbol)) {
         $len = count($this->parts);
         if ($len > 0 && is_string($this->parts[$len - 1])) {
             $this->parts[$len - 1] .= $symbol;
         } else {
             $this->parts[] = $symbol;
         }
         $this->length += strlen($symbol);
         $this->strLength += strlen($symbol);
     } elseif ($symbol instanceof \Traversable || is_array($symbol)) {
         $ret = [];
         foreach ($symbol as $part) {
             $ret[] = $this->push($part);
         }
         return $ret;
     } else {
         throw new \InvalidArgumentException(sprintf('Part type unsupported: %s', get_class($symbol)));
     }
     return $symbol;
 }
开发者ID:e1himself,项目名称:php-x-components,代码行数:34,代码来源:Buffer.php

示例5: leaveNode

 public function leaveNode(Node $node)
 {
     $type = $node->getType();
     if ($type == "Expr_BinaryOp_Concat") {
         if ($node->right) {
             //转为symbol
             $right_symbol = SymbolUtils::getSymbolByNode($node->right);
             $right_symbol != null && array_push($this->items, $right_symbol);
         }
         if ($node->left->getType() != "Expr_BinaryOp_Concat") {
             $left_symbol = SymbolUtils::getSymbolByNode($node->left);
             $left_symbol != null && array_push($this->items, $left_symbol);
         }
     } else {
         if ($type == "Scalar_Encapsed") {
             foreach ($node->parts as $item) {
                 if (!is_object($item)) {
                     $valueSymbol = new ValueSymbol();
                     $valueSymbol->setValue($item);
                     $valueSymbol != null && array_push($this->items, $valueSymbol);
                 } else {
                     $setItem = SymbolUtils::getSymbolByNode($item);
                     $setItem != null && array_push($this->items, $setItem);
                 }
             }
         }
     }
 }
开发者ID:getcode2git,项目名称:phpvulhunter,代码行数:28,代码来源:ConcatSymbol.class.php

示例6: 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

示例7: 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);
 }
开发者ID:phpro,项目名称:grumphp,代码行数:12,代码来源:NoExitStatementsVisitor.php

示例8: enterNode

 public function enterNode(Node $node)
 {
     if ($node->getType() == 'Stmt_Use') {
         foreach ($node->uses as $use) {
             $this->uses[] = $use;
         }
     }
     // echo $node->getType() . "\n";
     if (isset($node->class) && $node->class) {
         if ($node->class->getType() != 'Name_FullyQualified') {
             $this->names[] = $node->class;
         }
     }
     if (isset($node->extends) && $node->extends) {
         if ($node->extends->getType() != 'Name_FullyQualified') {
             $this->names[] = $node->extends;
         }
     }
     if (isset($node->implements) && $node->implements) {
         foreach ($node->implements as $implements) {
             if ($implements->getType() != 'Name_FullyQualified') {
                 $this->names[] = $implements;
             }
         }
     }
     if (isset($node->params)) {
         foreach ($node->params as $param) {
             if ($param->type && !is_string($param->type)) {
                 if ($param->type->getType() != 'Name_FullyQualified') {
                     $this->names[] = $param->type;
                 }
             }
         }
     }
 }
开发者ID:knuthelland,项目名称:phpimports,代码行数:35,代码来源:ScopeAnalyzer.php

示例9: enterNode

 public function enterNode(Node $node)
 {
     if (!empty($this->stack)) {
         $node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
     }
     $this->stack[] = $node;
 }
开发者ID:sourcerer-mike,项目名称:phpsemver,代码行数:7,代码来源:ParentVisitor.php

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

示例11: 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();
     }
 }
开发者ID:jolicode,项目名称:php7-checker,代码行数:29,代码来源:GlobalVariableRemovedChecker.php

示例12: 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

示例13: 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);
     }
 }
开发者ID:sadapon2008,项目名称:check-php-mbstring-by-yahoo,代码行数:7,代码来源:extract_string.php

示例14: 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

示例15: enterNode

 /**
  * 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;
 }
开发者ID:basilfx,项目名称:php-obfuscator,代码行数:32,代码来源:RemoveComments.php


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