public function PHP_Token_INTERFACE::getPackage

File

drupal/core/vendor/phpunit/php-token-stream/PHP/Token.php, line 528

Class

PHP_Token_INTERFACE

Code

public function getPackage() {
  $className = $this
    ->getName();
  $docComment = $this
    ->getDocblock();
  $result = array(
    'namespace' => '',
    'fullPackage' => '',
    'category' => '',
    'package' => '',
    'subpackage' => '',
  );
  for ($i = $this->id; $i; --$i) {
    if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) {
      $result['namespace'] = $this->tokenStream[$i]
        ->getName();
      break;
    }
  }
  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'] = $this
      ->arrayToName(explode('_', str_replace('\\', '_', $className)), '.');
  }
  return $result;
}