protected function PHP_Token_Stream::parse

4 calls to PHP_Token_Stream::parse()
PHP_Token_Stream::getClasses in drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php
PHP_Token_Stream::getFunctions in drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php
PHP_Token_Stream::getInterfaces in drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php
PHP_Token_Stream::getTraits in drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php
@since Method available since Release 1.1.0

File

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

Class

PHP_Token_Stream
A stream of PHP tokens.

Code

protected function parse() {
  $this->interfaces = array();
  $this->classes = array();
  $this->traits = array();
  $this->functions = array();
  $class = FALSE;
  $classEndLine = FALSE;
  $trait = FALSE;
  $traitEndLine = FALSE;
  $interface = FALSE;
  $interfaceEndLine = FALSE;
  foreach ($this->tokens as $token) {
    switch (get_class($token)) {
      case 'PHP_Token_HALT_COMPILER':
        return;
        break;
      case 'PHP_Token_INTERFACE':
        $interface = $token
          ->getName();
        $interfaceEndLine = $token
          ->getEndLine();
        $this->interfaces[$interface] = array(
          'methods' => array(),
          'parent' => $token
            ->getParent(),
          'keywords' => $token
            ->getKeywords(),
          'docblock' => $token
            ->getDocblock(),
          'startLine' => $token
            ->getLine(),
          'endLine' => $interfaceEndLine,
          'package' => $token
            ->getPackage(),
          'file' => $this->filename,
        );
        break;
      case 'PHP_Token_CLASS':
      case 'PHP_Token_TRAIT':
        $tmp = array(
          'methods' => array(),
          'parent' => $token
            ->getParent(),
          'interfaces' => $token
            ->getInterfaces(),
          'keywords' => $token
            ->getKeywords(),
          'docblock' => $token
            ->getDocblock(),
          'startLine' => $token
            ->getLine(),
          'endLine' => $token
            ->getEndLine(),
          'package' => $token
            ->getPackage(),
          'file' => $this->filename,
        );
        if ($token instanceof PHP_Token_CLASS) {
          $class = $token
            ->getName();
          $classEndLine = $token
            ->getEndLine();
          $this->classes[$class] = $tmp;
        }
        else {
          $trait = $token
            ->getName();
          $traitEndLine = $token
            ->getEndLine();
          $this->traits[$trait] = $tmp;
        }
        break;
      case 'PHP_Token_FUNCTION':
        $name = $token
          ->getName();
        $tmp = array(
          'docblock' => $token
            ->getDocblock(),
          'keywords' => $token
            ->getKeywords(),
          'visibility' => $token
            ->getVisibility(),
          'signature' => $token
            ->getSignature(),
          'startLine' => $token
            ->getLine(),
          'endLine' => $token
            ->getEndLine(),
          'ccn' => $token
            ->getCCN(),
          'file' => $this->filename,
        );
        if ($class === FALSE && $trait === FALSE && $interface === FALSE) {
          $this->functions[$name] = $tmp;
        }
        else {
          if ($class !== FALSE) {
            $this->classes[$class]['methods'][$name] = $tmp;
          }
          else {
            if ($trait !== FALSE) {
              $this->traits[$trait]['methods'][$name] = $tmp;
            }
            else {
              $this->interfaces[$interface]['methods'][$name] = $tmp;
            }
          }
        }
        break;
      case 'PHP_Token_CLOSE_CURLY':
        if ($classEndLine !== FALSE && $classEndLine == $token
          ->getLine()) {
          $class = FALSE;
          $classEndLine = FALSE;
        }
        else {
          if ($traitEndLine !== FALSE && $traitEndLine == $token
            ->getLine()) {
            $trait = FALSE;
            $traitEndLine = FALSE;
          }
          else {
            if ($interfaceEndLine !== FALSE && $interfaceEndLine == $token
              ->getLine()) {
              $interface = FALSE;
              $interfaceEndLine = FALSE;
            }
          }
        }
        break;
    }
  }
}