/** * Calculates the Weight Method Per Class metric, this method only counts * protected and public methods of parent classes. * * @param PHP_Depend_Code_Class $class The context class instance. * * @return integer */ private function _calculateWMCi(PHP_Depend_Code_Class $class) { // List of methods, this method only counts not overwritten methods. $ccn = array(); // First collect all methods of the context class foreach ($class->getMethods() as $m) { $ccn[$m->getName()] = $this->_cyclomaticAnalyzer->getCCN2($m); } // Get parent class and collect all non private methods. $parent = $class->getParentClass(); while ($parent !== null) { // Count all methods foreach ($parent->getMethods() as $m) { if (!$m->isPrivate() && !isset($methods[$m->getName()])) { $ccn[$m->getName()] = $this->_cyclomaticAnalyzer->getCCN2($m); } } // Fetch parent class $parent = $parent->getParentClass(); } return array_sum($ccn); }
/** * Tests that the {@link PHP_Depend_Code_Class::addMethod()} method adds a * method to the internal list and sets the context class as parent. * * @return void */ public function testAddMethodStoresNewlyAddedMethodInCollection() { $class = new PHP_Depend_Code_Class(__CLASS__); $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory()); $class->addMethod(new PHP_Depend_Code_Method(__FUNCTION__)); self::assertEquals(1, $class->getMethods()->count()); }
/** * Tests that a new {@link PHP_Depend_Code_Class} object returns an empty * {@link PHP_Depend_Code_NodeIterator} instance for methods. * * @return void * @covers PHP_Depend_Code_AbstractClassOrInterface * @covers PHP_Depend_Code_Class * @group pdepend * @group pdepend::code * @group unittest */ public function testGetMethodNodeIterator() { $class = new PHP_Depend_Code_Class('clazz', 0); $methods = $class->getMethods(); $this->assertEquals(0, $methods->count()); }