/**
  * Calculates lcom for file (and not for class)
  *
  * @param string $filename
  * @return Result
  */
 public function calculate($filename)
 {
     $rOOP = $this->classMap->getClassesIn($filename);
     $result = new Result($filename);
     $n = 0;
     $lcom = new LackOfCohesionOfMethods();
     foreach ($rOOP->getClasses() as $class) {
         $r = $lcom->calculate($class);
         $n += $r->getLcom();
     }
     $result->setLcom($n);
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Calculates system complexity
  *
  * @param string $filename
  * @return Result
  */
 public function calculate($filename)
 {
     $rOOP = $this->classMap->getClassesIn($filename);
     $result = new Result($filename);
     $len = 0;
     $sy = $dc = $sc = array();
     $calculator = new SystemComplexity();
     foreach ($rOOP->getClasses() as $class) {
         $r = $calculator->calculate($class);
         $len += sizeof($class->getMethods(), COUNT_NORMAL);
         $sy[] = $r->getTotalSystemComplexity();
         $dc[] = $r->getTotalDataComplexity();
         $sc[] = $r->getTotalStructuralComplexity();
     }
     if ($len > 0 && sizeof($dc, COUNT_NORMAL) > 0) {
         $result->setRelativeStructuralComplexity(round(array_sum($sc) / $len, 2))->setRelativeDataComplexity(round(array_sum($dc) / $len, 2))->setRelativeSystemComplexity(round(array_sum($sy) / $len, 2))->setTotalStructuralComplexity(array_sum($sc))->setTotalDataComplexity(array_sum($dc))->setTotalSystemComplexity(array_sum($dc) + array_sum($sc));
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Calculates coupling for file (and not for class)
  *
  * @param string $filename
  * @return Result
  */
 public function calculate($filename)
 {
     $rOOP = $this->classMap->getClassesIn($filename);
     $result = new Result($filename);
     // case of file doesn't contain any class
     if (null === $rOOP) {
         return $result;
     }
     $instability = $ce = $ca = 0;
     $classes = $rOOP->getClasses();
     foreach ($classes as $declaredClass) {
         $declaredClassCoupling = $this->couplingMap->get($declaredClass->getFullname());
         $ce += $declaredClassCoupling->getEfferentCoupling();
         $ca += $declaredClassCoupling->getAfferentCoupling();
     }
     if ($ca + $ce > 0) {
         $instability = $ce / ($ca + $ce);
     }
     $result->setAfferentCoupling($ca)->setEfferentCoupling($ce)->setInstability($instability);
     return $result;
 }