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


PHP PHP_Token_Stream::getTraits方法代码示例

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


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

示例1: getLinesToBeIgnored

 /**
  * Returns the lines of a source file that should be ignored.
  *
  * @param  string                     $filename
  * @return array
  * @throws PHP_CodeCoverage_Exception
  * @since  Method available since Release 2.0.0
  */
 private function getLinesToBeIgnored($filename)
 {
     if (!is_string($filename)) {
         throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     if (!isset($this->ignoredLines[$filename])) {
         $this->ignoredLines[$filename] = array();
         $ignore = false;
         $stop = false;
         $lines = file($filename);
         $numLines = count($lines);
         foreach ($lines as $index => $line) {
             if (!trim($line)) {
                 $this->ignoredLines[$filename][] = $index + 1;
             }
         }
         if ($this->cacheTokens) {
             $tokens = PHP_Token_Stream_CachingFactory::get($filename);
         } else {
             $tokens = new PHP_Token_Stream($filename);
         }
         $classes = array_merge($tokens->getClasses(), $tokens->getTraits());
         $tokens = $tokens->tokens();
         foreach ($tokens as $token) {
             switch (get_class($token)) {
                 case 'PHP_Token_COMMENT':
                 case 'PHP_Token_DOC_COMMENT':
                     $_token = trim($token);
                     $_line = trim($lines[$token->getLine() - 1]);
                     if ($_token == '// @codeCoverageIgnore' || $_token == '//@codeCoverageIgnore') {
                         $ignore = true;
                         $stop = true;
                     } elseif ($_token == '// @codeCoverageIgnoreStart' || $_token == '//@codeCoverageIgnoreStart') {
                         $ignore = true;
                     } elseif ($_token == '// @codeCoverageIgnoreEnd' || $_token == '//@codeCoverageIgnoreEnd') {
                         $stop = true;
                     }
                     if (!$ignore) {
                         $start = $token->getLine();
                         $end = $start + substr_count($token, "\n");
                         // Do not ignore the first line when there is a token
                         // before the comment
                         if (0 !== strpos($_token, $_line)) {
                             $start++;
                         }
                         for ($i = $start; $i < $end; $i++) {
                             $this->ignoredLines[$filename][] = $i;
                         }
                         // A DOC_COMMENT token or a COMMENT token starting with "/*"
                         // does not contain the final \n character in its text
                         if (0 === strpos($_token, '/*') && '*/' === substr(trim($lines[$i - 1]), -2)) {
                             $this->ignoredLines[$filename][] = $i;
                         }
                     }
                     break;
                 case 'PHP_Token_INTERFACE':
                 case 'PHP_Token_TRAIT':
                 case 'PHP_Token_CLASS':
                 case 'PHP_Token_FUNCTION':
                     $docblock = $token->getDocblock();
                     $this->ignoredLines[$filename][] = $token->getLine();
                     if (strpos($docblock, '@codeCoverageIgnore')) {
                         $endLine = $token->getEndLine();
                         for ($i = $token->getLine(); $i <= $endLine; $i++) {
                             $this->ignoredLines[$filename][] = $i;
                         }
                     } elseif ($token instanceof PHP_Token_INTERFACE || $token instanceof PHP_Token_TRAIT || $token instanceof PHP_Token_CLASS) {
                         if (empty($classes[$token->getName()]['methods'])) {
                             for ($i = $token->getLine(); $i <= $token->getEndLine(); $i++) {
                                 $this->ignoredLines[$filename][] = $i;
                             }
                         } else {
                             $firstMethod = array_shift($classes[$token->getName()]['methods']);
                             do {
                                 $lastMethod = array_pop($classes[$token->getName()]['methods']);
                             } while ($lastMethod !== null && substr($lastMethod['signature'], 0, 18) == 'anonymous function');
                             if ($lastMethod === null) {
                                 $lastMethod = $firstMethod;
                             }
                             for ($i = $token->getLine(); $i < $firstMethod['startLine']; $i++) {
                                 $this->ignoredLines[$filename][] = $i;
                             }
                             for ($i = $token->getEndLine(); $i > $lastMethod['endLine']; $i--) {
                                 $this->ignoredLines[$filename][] = $i;
                             }
                         }
                     }
                     break;
                 case 'PHP_Token_NAMESPACE':
                     $this->ignoredLines[$filename][] = $token->getEndLine();
                     // Intentional fallthrough
                 // Intentional fallthrough
//.........这里部分代码省略.........
开发者ID:Ingothq,项目名称:multiarmedbandit,代码行数:101,代码来源:CodeCoverage.php

示例2: processTraits

 /**
  * @param \PHP_Token_Stream $tokens
  */
 protected function processTraits(\PHP_Token_Stream $tokens)
 {
     $traits = $tokens->getTraits();
     unset($tokens);
     $link = $this->getId() . '.html#';
     foreach ($traits as $traitName => $trait) {
         $this->traits[$traitName] = ['traitName' => $traitName, 'methods' => [], 'startLine' => $trait['startLine'], 'executableLines' => 0, 'executedLines' => 0, 'ccn' => 0, 'coverage' => 0, 'crap' => 0, 'package' => $trait['package'], 'link' => $link . $trait['startLine']];
         $this->startLines[$trait['startLine']] =& $this->traits[$traitName];
         $this->endLines[$trait['endLine']] =& $this->traits[$traitName];
         foreach ($trait['methods'] as $methodName => $method) {
             $this->traits[$traitName]['methods'][$methodName] = $this->newMethod($methodName, $method, $link);
             $this->startLines[$method['startLine']] =& $this->traits[$traitName]['methods'][$methodName];
             $this->endLines[$method['endLine']] =& $this->traits[$traitName]['methods'][$methodName];
         }
     }
 }
开发者ID:thanghexp,项目名称:project,代码行数:19,代码来源:File.php

示例3: getLinesToBeIgnored

 /**
  * Returns the lines of a source file that should be ignored.
  *
  * @param  string  $filename
  * @param  boolean $cacheTokens
  * @return array
  * @throws PHP_CodeCoverage_Exception
  */
 public static function getLinesToBeIgnored($filename, $cacheTokens = TRUE)
 {
     if (!is_string($filename)) {
         throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     if (!is_bool($cacheTokens)) {
         throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(2, 'boolean');
     }
     if (!isset(self::$ignoredLines[$filename])) {
         self::$ignoredLines[$filename] = array();
         $ignore = FALSE;
         $stop = FALSE;
         $lines = file($filename);
         foreach ($lines as $index => $line) {
             if (!trim($line)) {
                 self::$ignoredLines[$filename][$index + 1] = TRUE;
             }
         }
         if ($cacheTokens) {
             $tokens = PHP_Token_Stream_CachingFactory::get($filename);
         } else {
             $tokens = new PHP_Token_Stream($filename);
         }
         $classes = array_merge($tokens->getClasses(), $tokens->getTraits());
         $tokens = $tokens->tokens();
         foreach ($tokens as $token) {
             switch (get_class($token)) {
                 case 'PHP_Token_COMMENT':
                 case 'PHP_Token_DOC_COMMENT':
                     $count = substr_count($token, "\n");
                     $line = $token->getLine();
                     for ($i = $line; $i < $line + $count; $i++) {
                         self::$ignoredLines[$filename][$i] = TRUE;
                     }
                     if ($token instanceof PHP_Token_DOC_COMMENT) {
                         // Workaround for the fact the DOC_COMMENT token
                         // does not include the final \n character in its
                         // text.
                         if (substr(trim($lines[$i - 1]), -2) == '*/') {
                             self::$ignoredLines[$filename][$i] = TRUE;
                         }
                         break;
                     }
                     $_token = trim($token);
                     if ($_token == '// @codeCoverageIgnore' || $_token == '//@codeCoverageIgnore') {
                         $ignore = TRUE;
                         $stop = TRUE;
                     } else {
                         if ($_token == '// @codeCoverageIgnoreStart' || $_token == '//@codeCoverageIgnoreStart') {
                             $ignore = TRUE;
                         } else {
                             if ($_token == '// @codeCoverageIgnoreEnd' || $_token == '//@codeCoverageIgnoreEnd') {
                                 $stop = TRUE;
                             }
                         }
                     }
                     break;
                 case 'PHP_Token_INTERFACE':
                 case 'PHP_Token_TRAIT':
                 case 'PHP_Token_CLASS':
                 case 'PHP_Token_FUNCTION':
                     $docblock = $token->getDocblock();
                     if (strpos($docblock, '@codeCoverageIgnore')) {
                         $endLine = $token->getEndLine();
                         for ($i = $token->getLine(); $i <= $endLine; $i++) {
                             self::$ignoredLines[$filename][$i] = TRUE;
                         }
                     } else {
                         if ($token instanceof PHP_Token_INTERFACE || $token instanceof PHP_Token_TRAIT || $token instanceof PHP_Token_CLASS) {
                             if (empty($classes[$token->getName()]['methods'])) {
                                 for ($i = $token->getLine(); $i <= $token->getEndLine(); $i++) {
                                     self::$ignoredLines[$filename][$i] = TRUE;
                                 }
                             } else {
                                 $firstMethod = array_shift($classes[$token->getName()]['methods']);
                                 $lastMethod = array_pop($classes[$token->getName()]['methods']);
                                 if ($lastMethod === NULL) {
                                     $lastMethod = $firstMethod;
                                 }
                                 for ($i = $token->getLine(); $i < $firstMethod['startLine']; $i++) {
                                     self::$ignoredLines[$filename][$i] = TRUE;
                                 }
                                 for ($i = $token->getEndLine(); $i > $lastMethod['endLine']; $i--) {
                                     self::$ignoredLines[$filename][$i] = TRUE;
                                 }
                             }
                         }
                     }
                     break;
                 case 'PHP_Token_INTERFACE':
                     $endLine = $token->getEndLine();
                     for ($i = $token->getLine(); $i <= $endLine; $i++) {
//.........这里部分代码省略.........
开发者ID:shinichi81,项目名称:Codeigniter-TDD-with-Hooks,代码行数:101,代码来源:Util.php


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