Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Merge [900].

  • Loading branch information...
commit 6679888567bbc7677b07c4d158a863b2411735e6 1 parent bb9772d
@sebastianbergmann authored
Showing with 41 additions and 0 deletions.
  1. +41 −0 PHPUnit/Util/Class.php
View
41 PHPUnit/Util/Class.php
@@ -64,6 +64,7 @@ class PHPUnit_Util_Class
{
protected static $buffer = array();
protected static $fileClassMap = array();
+ protected static $noc = array();
/**
* Starts the collection of loaded classes.
@@ -291,5 +292,45 @@ public static function getDIT($className)
{
return count(self::getHierarchy($className));
}
+
+ /**
+ * Returns the Number of Children (NOC) for a class.
+ *
+ * @param string $className
+ * @param boolean $clearCache
+ * @return integer
+ * @access public
+ * @static
+ * @since Method available since Release 3.1.6
+ */
+ public static function getNOC($className, $clearCache = FALSE)
+ {
+ if ($clearCache) {
+ self::$noc = array();
+ }
+
+ if (empty(self::$noc)) {
+ foreach (get_declared_classes() as $_className) {
+ $class = new ReflectionClass($_className);
+ $parent = $class->getParentClass();
+
+ if ($parent !== FALSE) {
+ $parentName = $parent->getName();
+
+ if (isset(self::$noc[$parentName])) {
+ self::$noc[$parentName]++;
+ } else {
+ self::$noc[$parentName] = 1;
+ }
+ }
+ }
+ }
+
+ if (isset(self::$noc[$className])) {
+ return self::$noc[$className];
+ } else {
+ return 0;
+ }
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.