PHPUnit_Util_Class::getPackageInformation PHP Method

getPackageInformation() public static method

Returns the package information of a user-defined class.
public static getPackageInformation ( string $className, string $docComment ) : array
$className string
$docComment string
return array
    public static function getPackageInformation($className, $docComment)
    {
        $result = array('namespace' => '', 'fullPackage' => '', 'category' => '', 'package' => '', 'subpackage' => '');
        if (strpos($className, '\\') !== FALSE) {
            $result['namespace'] = self::arrayToName(explode('\\', $className));
        }
        if (preg_match('/@category[\\s]+([\\.\\w]+)/', $docComment, $matches)) {
            $result['category'] = $matches[1];
        }
        if (preg_match('/@package[\\s]+([\\.\\w]+)/', $docComment, $matches)) {
            $result['package'] = $matches[1];
            $result['fullPackage'] = $matches[1];
        }
        if (preg_match('/@subpackage[\\s]+([\\.\\w]+)/', $docComment, $matches)) {
            $result['subpackage'] = $matches[1];
            $result['fullPackage'] .= '.' . $matches[1];
        }
        if (empty($result['fullPackage'])) {
            $result['fullPackage'] = self::arrayToName(explode('_', str_replace('\\', '_', $className)), '.');
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * Constructor.
  *
  * @param  ReflectionClass $class
  * @param  array           $codeCoverage
  */
 protected function __construct(ReflectionClass $class, &$codeCoverage = array())
 {
     $this->class = $class;
     $className = $class->getName();
     $packageInformation = PHPUnit_Util_Class::getPackageInformation($className);
     if (!empty($packageInformation['fullPackage'])) {
         $this->package = $packageInformation['fullPackage'];
     }
     $this->setCoverage($codeCoverage);
     $this->dit = count(PHPUnit_Util_Class::getHierarchy($class->getName())) - 1;
     $this->impl = count($class->getInterfaces());
     foreach ($this->class->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() == $className) {
             $this->methods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage);
         } else {
             $this->inheritedMethods[$method->getName()] = PHPUnit_Util_Metrics_Function::factory($method, $codeCoverage);
         }
     }
     $this->calculateAttributeMetrics();
     $this->calculateMethodMetrics();
     $this->calculateNumberOfChildren();
     $this->calculatePolymorphismFactor();
     $this->calculateDependencies();
 }
All Usage Examples Of PHPUnit_Util_Class::getPackageInformation