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


PHP XHPASTNode::selectDescendantsOftype方法代码示例

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


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

示例1: lintPHP54Features

 private function lintPHP54Features(XHPASTNode $root)
 {
     $indexes = $root->selectDescendantsOfType('n_INDEX_ACCESS');
     foreach ($indexes as $index) {
         switch ($index->getChildByIndex(0)->getTypeName()) {
             case 'n_FUNCTION_CALL':
             case 'n_METHOD_CALL':
                 $this->raiseLintAtNode($index->getChildByIndex(1), pht('The `%s` syntax was not introduced until PHP 5.4, but this ' . 'codebase targets an earlier version of PHP. You can rewrite ' . 'this expression using `%s`.', 'f()[...]', 'idx()'));
                 break;
         }
     }
     $literals = $root->selectDescendantsOftype('n_ARRAY_LITERAL');
     foreach ($literals as $literal) {
         $open_token = head($literal->getTokens())->getValue();
         if ($open_token == '[') {
             $this->raiseLintAtNode($literal, pht('The short array syntax ("[...]") was not introduced until ' . 'PHP 5.4, but this codebase targets an earlier version of PHP. ' . 'You can rewrite this expression using `array(...)` instead.'));
         }
     }
     $closures = $this->getAnonymousClosures($root);
     foreach ($closures as $closure) {
         $static_accesses = $closure->selectDescendantsOfType('n_CLASS_STATIC_ACCESS');
         foreach ($static_accesses as $static_access) {
             $class = $static_access->getChildByIndex(0);
             if ($class->getTypeName() != 'n_CLASS_NAME') {
                 continue;
             }
             if (strtolower($class->getConcreteString()) != 'self') {
                 continue;
             }
             $this->raiseLintAtNode($class, pht('The use of `%s` in an anonymous closure is not ' . 'available before PHP 5.4.', 'self'));
         }
         $property_accesses = $closure->selectDescendantsOfType('n_OBJECT_PROPERTY_ACCESS');
         foreach ($property_accesses as $property_access) {
             $variable = $property_access->getChildByIndex(0);
             if ($variable->getTypeName() != 'n_VARIABLE') {
                 continue;
             }
             if ($variable->getConcreteString() != '$this') {
                 continue;
             }
             $this->raiseLintAtNode($variable, pht('The use of `%s` in an anonymous closure is not ' . 'available before PHP 5.4.', '$this'));
         }
     }
     $numeric_scalars = $root->selectDescendantsOfType('n_NUMERIC_SCALAR');
     foreach ($numeric_scalars as $numeric_scalar) {
         if (preg_match('/^0b[01]+$/i', $numeric_scalar->getConcreteString())) {
             $this->raiseLintAtNode($numeric_scalar, pht('Binary integer literals are not available before PHP 5.4.'));
         }
     }
 }
开发者ID:benchling,项目名称:arcanist,代码行数:50,代码来源:ArcanistPHPCompatibilityXHPASTLinterRule.php


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