/** * Initializes a empty metric container for the given class node. * * @param \PDepend\Source\AST\ASTClass $class * @return void * @since 0.9.10 */ private function initNodeMetricsForClass(ASTClass $class) { $id = $class->getId(); if (isset($this->nodeMetrics[$id])) { return; } ++$this->numberOfClasses; $this->nodeMetrics[$id] = array(self::M_DEPTH_OF_INHERITANCE_TREE => 0, self::M_NUMBER_OF_ADDED_METHODS => 0, self::M_NUMBER_OF_DERIVED_CLASSES => 0, self::M_NUMBER_OF_OVERWRITTEN_METHODS => 0); foreach ($class->getParentClasses() as $parent) { $this->initNodeMetricsForClass($parent); } }
/** * testGetParentClassesReturnsEmptyArrayByDefault * * @return void */ public function testGetParentClassesReturnsEmptyArrayByDefault() { $class = new ASTClass(__CLASS__); $this->assertSame(array(), $class->getParentClasses()); }
/** * Calculates the Variables Inheritance of a class metric, this method only * counts protected and public properties of parent classes. * * @param \PDepend\Source\AST\ASTClass $class The context class instance. * @return integer */ private function calculateVarsi(ASTClass $class) { // List of properties, this method only counts not overwritten properties $properties = array(); // Collect all properties of the context class foreach ($class->getProperties() as $prop) { $properties[$prop->getName()] = true; } foreach ($class->getParentClasses() as $parent) { foreach ($parent->getProperties() as $prop) { if (!$prop->isPrivate() && !isset($properties[$prop->getName()])) { $properties[$prop->getName()] = true; } } } return count($properties); }