This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Refactored: clsa and clsc metric inlined.

Now the node count analyzer calculates the CLSA und CLSC metrics,
instead of the hierarchy analyzer.
  • Loading branch information...
manuelpichler committed May 16, 2012
1 parent f065c8e commit 2167606b8dcec1f68cd2c1f70a1835178f64249a
Showing with 238 additions and 465 deletions.
  1. +10 −0 src/main/php/PHP/Depend/AST/Class.php
  2. +0 −6 src/main/php/PHP/Depend/Metrics/Hierarchy/Analyzer.php
  3. +27 −10 src/main/php/PHP/Depend/Metrics/NodeCount/Analyzer.php
  4. +0 −27 src/test/php/PHP/Depend/Metrics/Hierarchy/AnalyzerTest.php
  5. +97 −113 src/test/php/PHP/Depend/Metrics/NodeCount/AnalyzerTest.php
  6. +0 −67 src/test/resources/files/Metrics/Hierarchy/testCalculatesExpectedNumberOfAbstractClasses.php
  7. +0 −67 src/test/resources/files/Metrics/Hierarchy/testCalculatesExpectedNumberOfConcreteClasses.php
  8. +0 −15 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfClassesInPackages.php
  9. +0 −17 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfClassesInProject.php
  10. +0 −15 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfFunctionsInPackages.php
  11. +0 −15 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfFunctionsInProject.php
  12. +0 −15 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfInterfacesInPackages.php
  13. +0 −18 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfInterfacesInProject.php
  14. +0 −30 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfMethodsInPackages.php
  15. +0 −15 src/test/resources/files/Metrics/NodeCount/testCalculatesExpectedNumberOfPackages.php
  16. +48 −0 src/test/resources/files/Metrics/NodeCount/testGetNodeMetricsOnNamespace.php
  17. +56 −0 src/test/resources/files/Metrics/NodeCount/testGetProjectMetricsReturnsExpectedSetOfMetrics.php
  18. +0 −35 src/test/resources/files/Metrics/NodeCount/testNumberOfMethodsInProject.php
@@ -150,6 +150,16 @@ public function isUserDefined()
return $this->attributes['user_defined'];
}
+ /**
+ * Returns <b>true</b> when this class was declared as abstract.
+ *
+ * @return boolean
+ */
+ public function isAbstract()
+ {
+ return ( ( $this->type & self::MODIFIER_ABSTRACT ) === self::MODIFIER_ABSTRACT );
+ }
+
/**
* Magic wake up method that will register this object in the global node
* reference context.
@@ -81,12 +81,6 @@ class PHP_Depend_Metrics_Hierarchy_Analyzer /* TODO 2.0
*/
const CLAZZ = __CLASS__;
- /**
- * Metrics provided by the analyzer implementation.
- */
- const M_NUMBER_OF_ABSTRACT_CLASSES = 'clsa',
- M_NUMBER_OF_CONCRETE_CLASSES = 'clsc';
-
/**
* Number of all analyzed functions.
*
@@ -69,11 +69,13 @@ class PHP_Depend_Metrics_NodeCount_Analyzer extends PHP_Depend_Metrics_AbstractA
/**
* Metrics provided by the analyzer implementation.
*/
- const M_NUMBER_OF_PACKAGES = 'nop',
- M_NUMBER_OF_CLASSES = 'noc',
- M_NUMBER_OF_INTERFACES = 'noi',
- M_NUMBER_OF_METHODS = 'nom',
- M_NUMBER_OF_FUNCTIONS = 'nof';
+ const M_NUMBER_OF_PACKAGES = 'nop',
+ M_NUMBER_OF_CLASSES = 'noc',
+ M_NUMBER_OF_INTERFACES = 'noi',
+ M_NUMBER_OF_METHODS = 'nom',
+ M_NUMBER_OF_FUNCTIONS = 'nof',
+ M_NUMBER_OF_ABSTRACT_CLASSES = 'clsa',
+ M_NUMBER_OF_CONCRETE_CLASSES = 'clsc';
/**
* Number Of Packages.
@@ -89,6 +91,13 @@ class PHP_Depend_Metrics_NodeCount_Analyzer extends PHP_Depend_Metrics_AbstractA
*/
private $numberOfClasses = 0;
+ /**
+ * Number of abstract classes.
+ *
+ * @var integer
+ */
+ private $numberOfAbstractClasses = 0;
+
/**
* Number Of Interfaces.
*
@@ -163,11 +172,13 @@ public function getNodeMetrics( $node )
public function getProjectMetrics()
{
return array(
- self::M_NUMBER_OF_PACKAGES => $this->numberOfPackages,
- self::M_NUMBER_OF_CLASSES => $this->numberOfClasses,
- self::M_NUMBER_OF_INTERFACES => $this->numberOfInterfaces,
- self::M_NUMBER_OF_METHODS => $this->numberOfMethods,
- self::M_NUMBER_OF_FUNCTIONS => $this->numberOfFunctions
+ self::M_NUMBER_OF_PACKAGES => $this->numberOfPackages,
+ self::M_NUMBER_OF_CLASSES => $this->numberOfClasses,
+ self::M_NUMBER_OF_INTERFACES => $this->numberOfInterfaces,
+ self::M_NUMBER_OF_METHODS => $this->numberOfMethods,
+ self::M_NUMBER_OF_FUNCTIONS => $this->numberOfFunctions,
+ self::M_NUMBER_OF_ABSTRACT_CLASSES => $this->numberOfAbstractClasses,
+ self::M_NUMBER_OF_CONCRETE_CLASSES => ( $this->numberOfClasses - $this->numberOfAbstractClasses )
);
}
@@ -184,6 +195,11 @@ public function visitClassBefore( PHP_Depend_AST_Class $class, $data = null )
++$this->numberOfClasses;
+ if ( $class->isAbstract() )
+ {
+ ++$this->numberOfAbstractClasses;
+ }
+
$this->metrics[$class->getId()] = array( self::M_NUMBER_OF_METHODS => 0 );
$this->updateNamespace( $class->getNamespace(), self::M_NUMBER_OF_CLASSES );
@@ -221,6 +237,7 @@ public function visitInterfaceBefore( PHP_Depend_AST_Interface $interface, $data
* @param PHP_Depend_AST_Method $method
* @param mixed $data
* @return mixed
+ * @todo Do not count methods declared in an interface
*/
public function visitMethodBefore( PHP_Depend_AST_Method $method, $data = null )
{
@@ -66,33 +66,6 @@
*/
class PHP_Depend_Metrics_Hierarchy_AnalyzerTest extends PHP_Depend_Metrics_AbstractTest
{
- /**
- * testCalculatesExpectedNumberOfAbstractClasses
- *
- * @return void
- */
- public function testCalculatesExpectedNumberOfAbstractClasses()
- {
- $analyzer = new PHP_Depend_Metrics_Hierarchy_Analyzer();
- $analyzer->analyze(self::parseTestCaseSource(__METHOD__));
-
- $metrics = $analyzer->getProjectMetrics();
- self::assertEquals(1, $metrics['clsa']);
- }
-
- /**
- * testCalculatesExpectedNumberOfConcreteClasses
- *
- * @return void
- */
- public function testCalculatesExpectedNumberOfConcreteClasses()
- {
- $analyzer = new PHP_Depend_Metrics_Hierarchy_Analyzer();
- $analyzer->analyze(self::parseTestCaseSource(__METHOD__));
-
- $metrics = $analyzer->getProjectMetrics();
- self::assertEquals(2, $metrics['clsc']);
- }
/**
* testAnalyzerIgnoresClassesThatAreNotUserDefined
Oops, something went wrong.

0 comments on commit 2167606

Please sign in to comment.