You are here

class PHP_Token_INTERFACE in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/php-token-stream/src/Token.php \PHP_Token_INTERFACE

Hierarchy

Expanded class hierarchy of PHP_Token_INTERFACE

2 string references to 'PHP_Token_INTERFACE'
PHP_CodeCoverage::getLinesToBeIgnored in vendor/phpunit/php-code-coverage/src/CodeCoverage.php
Returns the lines of a source file that should be ignored.
PHP_Token_Stream::parse in vendor/phpunit/php-token-stream/src/Token/Stream.php

File

vendor/phpunit/php-token-stream/src/Token.php, line 444

View source
class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility {

  /**
   * @var array
   */
  protected $interfaces;

  /**
   * @return string
   */
  public function getName() {
    return (string) $this->tokenStream[$this->id + 2];
  }

  /**
   * @return boolean
   */
  public function hasParent() {
    return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS;
  }

  /**
   * @return array
   */
  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;
  }

  /**
   * @param  array  $parts
   * @param  string $join
   * @return string
   */
  protected function arrayToName(array $parts, $join = '\\') {
    $result = '';
    if (count($parts) > 1) {
      array_pop($parts);
      $result = join($join, $parts);
    }
    return $result;
  }

  /**
   * @return boolean|string
   */
  public function getParent() {
    if (!$this
      ->hasParent()) {
      return false;
    }
    $i = $this->id + 6;
    $tokens = $this->tokenStream
      ->tokens();
    $className = (string) $tokens[$i];
    while (isset($tokens[$i + 1]) && !$tokens[$i + 1] instanceof PHP_Token_WHITESPACE) {
      $className .= (string) $tokens[++$i];
    }
    return $className;
  }

  /**
   * @return boolean
   */
  public function hasInterfaces() {
    return isset($this->tokenStream[$this->id + 4]) && $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS || isset($this->tokenStream[$this->id + 8]) && $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS;
  }

  /**
   * @return array|boolean
   */
  public function getInterfaces() {
    if ($this->interfaces !== null) {
      return $this->interfaces;
    }
    if (!$this
      ->hasInterfaces()) {
      return $this->interfaces = false;
    }
    if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) {
      $i = $this->id + 3;
    }
    else {
      $i = $this->id + 7;
    }
    $tokens = $this->tokenStream
      ->tokens();
    while (!$tokens[$i + 1] instanceof PHP_Token_OPEN_CURLY) {
      $i++;
      if ($tokens[$i] instanceof PHP_Token_STRING) {
        $this->interfaces[] = (string) $tokens[$i];
      }
    }
    return $this->interfaces;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PHP_Token::$id protected property
PHP_Token::$line protected property
PHP_Token::$text protected property
PHP_Token::$tokenStream protected property
PHP_Token::getLine public function
PHP_Token::__construct public function Constructor.
PHP_Token::__toString public function
PHP_TokenWithScope::$endTokenId protected property
PHP_TokenWithScope::getDocblock public function Get the docblock for this token
PHP_TokenWithScope::getEndLine public function
PHP_TokenWithScope::getEndTokenId public function
PHP_TokenWithScopeAndVisibility::getKeywords public function
PHP_TokenWithScopeAndVisibility::getVisibility public function
PHP_Token_INTERFACE::$interfaces protected property
PHP_Token_INTERFACE::arrayToName protected function
PHP_Token_INTERFACE::getInterfaces public function
PHP_Token_INTERFACE::getName public function 1
PHP_Token_INTERFACE::getPackage public function
PHP_Token_INTERFACE::getParent public function
PHP_Token_INTERFACE::hasInterfaces public function
PHP_Token_INTERFACE::hasParent public function