コード例 #1
0
ファイル: LocTest.php プロジェクト: truffo/PhpMetrics
 public function testLocResultCanBeConvertedToArray()
 {
     $result = new \Hal\Metrics\Complexity\Text\Length\Result();
     $array = $result->asArray();
     $this->assertArrayHasKey('loc', $array);
     $this->assertArrayHasKey('logicalLoc', $array);
 }
コード例 #2
0
 /**
  * Calculates Maintainability Index
  *
  * @param \Hal\Metrics\Complexity\Text\Halstead\Result $rHalstead
  * @param \Hal\Metrics\Complexity\Text\Length\Result $rLoc
  * @param \Hal\Metrics\Complexity\Component\McCabe\Result $rMcCabe
  * @return Result
  */
 public function calculate(\Hal\Metrics\Complexity\Text\Halstead\Result $rHalstead, \Hal\Metrics\Complexity\Text\Length\Result $rLoc, \Hal\Metrics\Complexity\Component\McCabe\Result $rMcCabe)
 {
     $result = new Result();
     $result->setMaintainabilityIndexWithoutComment(max((171 - 5.2 * \log($rHalstead->getVolume()) - 0.23 * $rMcCabe->getCyclomaticComplexityNumber() - 16.2 * \log($rLoc->getLogicalLoc())) * 100 / 171, 0));
     // comment weight
     if ($rLoc->getLoc() > 0) {
         $CM = $rLoc->getCommentLoc() / $rLoc->getLoc();
         $result->setCommentWeight(50 * sin(sqrt(2.4 * $CM)));
     }
     return $result;
 }
コード例 #3
0
ファイル: Loc.php プロジェクト: YuraLukashik/PhpMetrics
 /**
  * Calculates Lines of code
  *
  * @param string $filename
  * @param TokenCollection $tokens
  * @return Result
  */
 public function calculate($filename, $tokens)
 {
     $info = new Result();
     $cloc = $lloc = 0;
     foreach ($tokens as $token) {
         switch ($token->getType()) {
             case T_STRING:
                 if (';' == $token->getValue()) {
                     $lloc++;
                 }
                 break;
             case T_COMMENT:
                 $cloc++;
                 break;
             case T_DOC_COMMENT:
                 $cloc += count(preg_split('/\\r\\n|\\r|\\n/', $token->getValue()));
                 break;
         }
     }
     $content = file_get_contents($filename);
     $info->setLoc(count(preg_split('/\\r\\n|\\r|\\n/', $content)) - 1)->setCommentLoc($cloc)->setLogicalLoc($lloc);
     return $info;
 }