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


PHP PHP_CodeCoverage_Util::crap方法代码示例

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


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

示例1: process

 /**
  * @param  PHP_CodeCoverage $coverage
  * @param  string           $target
  * @param  string           $name
  * @return string
  */
 public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL)
 {
     $document = new DOMDocument('1.0', 'UTF-8');
     $document->formatOutput = TRUE;
     $root = $document->createElement('coverage');
     $root->setAttribute('generated', (int) $_SERVER['REQUEST_TIME']);
     $document->appendChild($root);
     $project = $document->createElement('project');
     $project->setAttribute('timestamp', (int) $_SERVER['REQUEST_TIME']);
     if (is_string($name)) {
         $project->setAttribute('name', $name);
     }
     $root->appendChild($project);
     $files = $coverage->getSummary();
     $packages = array();
     $projectStatistics = array('files' => 0, 'loc' => 0, 'ncloc' => 0, 'classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
     foreach ($files as $filename => $data) {
         $namespace = 'global';
         if (file_exists($filename)) {
             $fileStatistics = array('classes' => 0, 'methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
             $file = $document->createElement('file');
             $file->setAttribute('name', $filename);
             $tokens = PHP_Token_Stream_CachingFactory::get($filename);
             $classesInFile = $tokens->getClasses();
             $linesOfCode = $tokens->getLinesOfCode();
             unset($tokens);
             $ignoredLines = PHP_CodeCoverage_Util::getLinesToBeIgnored($filename);
             $lines = array();
             foreach ($classesInFile as $className => $_class) {
                 $classStatistics = array('methods' => 0, 'coveredMethods' => 0, 'conditionals' => 0, 'coveredConditionals' => 0, 'statements' => 0, 'coveredStatements' => 0);
                 foreach ($_class['methods'] as $methodName => $method) {
                     $classStatistics['methods']++;
                     $methodCount = 0;
                     $methodLines = 0;
                     $methodLinesCovered = 0;
                     for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
                         if (isset($ignoredLines[$i])) {
                             continue;
                         }
                         $add = TRUE;
                         $count = 0;
                         if (isset($files[$filename][$i])) {
                             if ($files[$filename][$i] != -2) {
                                 $classStatistics['statements']++;
                                 $methodLines++;
                             }
                             if (is_array($files[$filename][$i])) {
                                 $classStatistics['coveredStatements']++;
                                 $methodLinesCovered++;
                                 $count = count($files[$filename][$i]);
                             } else {
                                 if ($files[$filename][$i] == -2) {
                                     $add = FALSE;
                                 }
                             }
                         } else {
                             $add = FALSE;
                         }
                         $methodCount = max($methodCount, $count);
                         if ($add) {
                             $lines[$i] = array('count' => $count, 'type' => 'stmt');
                         }
                     }
                     if ($methodCount > 0) {
                         $classStatistics['coveredMethods']++;
                     }
                     $lines[$method['startLine']] = array('count' => $methodCount, 'crap' => PHP_CodeCoverage_Util::crap($method['ccn'], PHP_CodeCoverage_Util::percent($methodLinesCovered, $methodLines)), 'type' => 'method', 'name' => $methodName);
                 }
                 $package = PHP_CodeCoverage_Util::getPackageInformation($className, $_class['docblock']);
                 if (!empty($package['namespace'])) {
                     $namespace = $package['namespace'];
                 }
                 $class = $document->createElement('class');
                 $class->setAttribute('name', $className);
                 $class->setAttribute('namespace', $namespace);
                 if (!empty($package['fullPackage'])) {
                     $class->setAttribute('fullPackage', $package['fullPackage']);
                 }
                 if (!empty($package['category'])) {
                     $class->setAttribute('category', $package['category']);
                 }
                 if (!empty($package['package'])) {
                     $class->setAttribute('package', $package['package']);
                 }
                 if (!empty($package['subpackage'])) {
                     $class->setAttribute('subpackage', $package['subpackage']);
                 }
                 $file->appendChild($class);
                 $metrics = $document->createElement('metrics');
                 $metrics->setAttribute('methods', $classStatistics['methods']);
                 $metrics->setAttribute('coveredmethods', $classStatistics['coveredMethods']);
                 $metrics->setAttribute('conditionals', $classStatistics['conditionals']);
                 $metrics->setAttribute('coveredconditionals', $classStatistics['coveredConditionals']);
                 $metrics->setAttribute('statements', $classStatistics['statements']);
//.........这里部分代码省略.........
开发者ID:redlion09,项目名称:pcppi,代码行数:101,代码来源:Clover.php

示例2: calculateStatistics

 /**
  * Calculates coverage statistics for the file.
  *
  */
 protected function calculateStatistics()
 {
     $this->processClasses();
     $this->processFunctions();
     $max = count($this->codeLines);
     for ($lineNumber = 1; $lineNumber <= $max; $lineNumber++) {
         if (isset($this->startLines[$lineNumber])) {
             // Start line of a class.
             if (isset($this->startLines[$lineNumber]['methods'])) {
                 $currentClass =& $this->startLines[$lineNumber];
             } else {
                 $currentMethod =& $this->startLines[$lineNumber];
             }
         }
         if (isset($this->executedLines[$lineNumber])) {
             // Array: Line is executable and was executed.
             if (is_array($this->executedLines[$lineNumber])) {
                 if (isset($currentClass)) {
                     $currentClass['executableLines']++;
                     $currentClass['executedLines']++;
                 }
                 if (isset($currentMethod)) {
                     $currentMethod['executableLines']++;
                     $currentMethod['executedLines']++;
                 }
                 $this->numExecutableLines++;
                 $this->numExecutedLines++;
             } else {
                 if ($this->executedLines[$lineNumber] == -1) {
                     if (isset($currentClass)) {
                         $currentClass['executableLines']++;
                     }
                     if (isset($currentMethod)) {
                         $currentMethod['executableLines']++;
                     }
                     $this->numExecutableLines++;
                     if (isset($this->ignoredLines[$lineNumber])) {
                         if (isset($currentClass)) {
                             $currentClass['executedLines']++;
                         }
                         if (isset($currentMethod)) {
                             $currentMethod['executedLines']++;
                         }
                         $this->numExecutedLines++;
                     }
                 }
             }
         }
         if (isset($this->endLines[$lineNumber])) {
             // End line of a class.
             if (isset($this->endLines[$lineNumber]['methods'])) {
                 unset($currentClass);
             } else {
                 unset($currentMethod);
             }
         }
     }
     foreach ($this->classes as $className => &$class) {
         foreach ($class['methods'] as &$method) {
             if ($method['executableLines'] > 0) {
                 $method['coverage'] = $method['executedLines'] / $method['executableLines'] * 100;
             } else {
                 $method['coverage'] = 100;
             }
             $method['crap'] = PHP_CodeCoverage_Util::crap($method['ccn'], $method['coverage']);
             $class['ccn'] += $method['ccn'];
         }
         if ($className != '*') {
             if ($class['executableLines'] > 0) {
                 $class['coverage'] = $class['executedLines'] / $class['executableLines'] * 100;
             } else {
                 $class['coverage'] = 100;
             }
             if ($class['coverage'] == 100) {
                 $this->numTestedClasses++;
             }
             $class['crap'] = PHP_CodeCoverage_Util::crap($class['ccn'], $class['coverage']);
         }
     }
 }
开发者ID:reflectivedevelopment,项目名称:jfh-lib,代码行数:84,代码来源:File.php

示例3: calculateStatistics

 /**
  * Calculates coverage statistics for the file.
  */
 protected function calculateStatistics()
 {
     if ($this->cacheTokens) {
         $tokens = PHP_Token_Stream_CachingFactory::get($this->getPath());
     } else {
         $tokens = new PHP_Token_Stream($this->getPath());
     }
     $this->processClasses($tokens);
     $this->processTraits($tokens);
     $this->processFunctions($tokens);
     $this->linesOfCode = $tokens->getLinesOfCode();
     unset($tokens);
     for ($lineNumber = 1; $lineNumber <= $this->linesOfCode['loc']; $lineNumber++) {
         if (isset($this->startLines[$lineNumber])) {
             // Start line of a class.
             if (isset($this->startLines[$lineNumber]['className'])) {
                 $currentClass =& $this->startLines[$lineNumber];
             } else {
                 if (isset($this->startLines[$lineNumber]['traitName'])) {
                     $currentTrait =& $this->startLines[$lineNumber];
                 } else {
                     if (isset($this->startLines[$lineNumber]['methodName'])) {
                         $currentMethod =& $this->startLines[$lineNumber];
                     } else {
                         if (isset($this->startLines[$lineNumber]['functionName'])) {
                             $currentFunction =& $this->startLines[$lineNumber];
                         }
                     }
                 }
             }
         }
         if (!isset($this->ignoredLines[$lineNumber]) && isset($this->coverageData[$lineNumber]) && $this->coverageData[$lineNumber] !== NULL) {
             if (isset($currentClass)) {
                 $currentClass['executableLines']++;
             }
             if (isset($currentTrait)) {
                 $currentTrait['executableLines']++;
             }
             if (isset($currentMethod)) {
                 $currentMethod['executableLines']++;
             }
             if (isset($currentFunction)) {
                 $currentFunction['executableLines']++;
             }
             $this->numExecutableLines++;
             if (count($this->coverageData[$lineNumber]) > 0 || isset($this->ignoredLines[$lineNumber])) {
                 if (isset($currentClass)) {
                     $currentClass['executedLines']++;
                 }
                 if (isset($currentTrait)) {
                     $currentTrait['executedLines']++;
                 }
                 if (isset($currentMethod)) {
                     $currentMethod['executedLines']++;
                 }
                 if (isset($currentFunction)) {
                     $currentFunction['executedLines']++;
                 }
                 $this->numExecutedLines++;
             }
         }
         if (isset($this->endLines[$lineNumber])) {
             // End line of a class.
             if (isset($this->endLines[$lineNumber]['className'])) {
                 unset($currentClass);
             } else {
                 if (isset($this->endLines[$lineNumber]['traitName'])) {
                     unset($currentTrait);
                 } else {
                     if (isset($this->endLines[$lineNumber]['methodName'])) {
                         unset($currentMethod);
                     } else {
                         if (isset($this->endLines[$lineNumber]['functionName'])) {
                             unset($currentFunction);
                         }
                     }
                 }
             }
         }
     }
     foreach ($this->traits as $traitName => &$trait) {
         foreach ($trait['methods'] as &$method) {
             if ($method['executableLines'] > 0) {
                 $method['coverage'] = $method['executedLines'] / $method['executableLines'] * 100;
             } else {
                 $method['coverage'] = 100;
             }
             $method['crap'] = PHP_CodeCoverage_Util::crap($method['ccn'], $method['coverage']);
             $trait['ccn'] += $method['ccn'];
         }
         if ($trait['executableLines'] > 0) {
             $trait['coverage'] = $trait['executedLines'] / $trait['executableLines'] * 100;
         } else {
             $trait['coverage'] = 100;
         }
         if ($trait['coverage'] == 100) {
             $this->numTestedClasses++;
//.........这里部分代码省略.........
开发者ID:staabm,项目名称:redaxo,代码行数:101,代码来源:File.php

示例4: process

 /**
  * @param  PHP_CodeCoverage $coverage
  * @param  string           $target
  * @param  string           $name
  * @return string
  */
 public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL)
 {
     $xmlDocument = new DOMDocument('1.0', 'UTF-8');
     $xmlDocument->formatOutput = TRUE;
     $xmlCoverage = $xmlDocument->createElement('coverage');
     $xmlCoverage->setAttribute('generated', (int) $_SERVER['REQUEST_TIME']);
     $xmlDocument->appendChild($xmlCoverage);
     $xmlProject = $xmlDocument->createElement('project');
     $xmlProject->setAttribute('timestamp', (int) $_SERVER['REQUEST_TIME']);
     if (is_string($name)) {
         $xmlProject->setAttribute('name', $name);
     }
     $xmlCoverage->appendChild($xmlProject);
     $packages = array();
     $report = $coverage->getReport();
     unset($coverage);
     foreach ($report as $item) {
         $namespace = 'global';
         if (!$item instanceof PHP_CodeCoverage_Report_Node_File) {
             continue;
         }
         $xmlFile = $xmlDocument->createElement('file');
         $xmlFile->setAttribute('name', $item->getPath());
         $classes = array_merge($item->getClasses(), $item->getTraits());
         $coverage = $item->getCoverageData();
         $lines = array();
         $ignoredLines = $item->getIgnoredLines();
         foreach ($classes as $className => $class) {
             $classStatements = 0;
             $coveredClassStatements = 0;
             $coveredMethods = 0;
             foreach ($class['methods'] as $methodName => $method) {
                 $methodCount = 0;
                 $methodLines = 0;
                 $methodLinesCovered = 0;
                 for ($i = $method['startLine']; $i <= $method['endLine']; $i++) {
                     if (isset($ignoredLines[$i])) {
                         continue;
                     }
                     $add = TRUE;
                     $count = 0;
                     if (isset($coverage[$i])) {
                         if ($coverage[$i] !== NULL) {
                             $classStatements++;
                             $methodLines++;
                         } else {
                             $add = FALSE;
                         }
                         $count = count($coverage[$i]);
                         if ($count > 0) {
                             $coveredClassStatements++;
                             $methodLinesCovered++;
                         }
                     } else {
                         $add = FALSE;
                     }
                     $methodCount = max($methodCount, $count);
                     if ($add) {
                         $lines[$i] = array('count' => $count, 'type' => 'stmt');
                     }
                 }
                 if ($methodCount > 0) {
                     $coveredMethods++;
                 }
                 $lines[$method['startLine']] = array('count' => $methodCount, 'crap' => PHP_CodeCoverage_Util::crap($method['ccn'], PHP_CodeCoverage_Util::percent($methodLinesCovered, $methodLines)), 'type' => 'method', 'name' => $methodName);
             }
             if (!empty($class['package']['namespace'])) {
                 $namespace = $class['package']['namespace'];
             }
             $xmlClass = $xmlDocument->createElement('class');
             $xmlClass->setAttribute('name', $className);
             $xmlClass->setAttribute('namespace', $namespace);
             if (!empty($class['package']['fullPackage'])) {
                 $xmlClass->setAttribute('fullPackage', $class['package']['fullPackage']);
             }
             if (!empty($class['package']['category'])) {
                 $xmlClass->setAttribute('category', $class['package']['category']);
             }
             if (!empty($class['package']['package'])) {
                 $xmlClass->setAttribute('package', $class['package']['package']);
             }
             if (!empty($class['package']['subpackage'])) {
                 $xmlClass->setAttribute('subpackage', $class['package']['subpackage']);
             }
             $xmlFile->appendChild($xmlClass);
             $xmlMetrics = $xmlDocument->createElement('metrics');
             $xmlMetrics->setAttribute('methods', count($class['methods']));
             $xmlMetrics->setAttribute('coveredmethods', $coveredMethods);
             $xmlMetrics->setAttribute('conditionals', 0);
             $xmlMetrics->setAttribute('coveredconditionals', 0);
             $xmlMetrics->setAttribute('statements', $classStatements);
             $xmlMetrics->setAttribute('coveredstatements', $coveredClassStatements);
             $xmlMetrics->setAttribute('elements', count($class['methods']) + $classStatements);
             $xmlMetrics->setAttribute('coveredelements', $coveredMethods + $coveredClassStatements);
//.........这里部分代码省略.........
开发者ID:nbalonso,项目名称:MunkiFace,代码行数:101,代码来源:Clover.php

示例5: testCrap

 /**
  * @covers PHP_CodeCoverage_Util::crap
  */
 public function testCrap()
 {
     $this->assertEquals(6, PHP_CodeCoverage_Util::crap(2, 0));
     $this->assertEquals(2, PHP_CodeCoverage_Util::crap(2, 95));
     $this->assertEquals(2.5, PHP_CodeCoverage_Util::crap(2, 50));
 }
开发者ID:reflectivedevelopment,项目名称:jfh-lib,代码行数:9,代码来源:UtilTest.php


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