當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。