You are here

class PHP_Token_FUNCTION in Zircon Profile 8

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

Hierarchy

Expanded class hierarchy of PHP_Token_FUNCTION

2 string references to 'PHP_Token_FUNCTION'
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 281

View source
class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility {

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

  /**
   * @var integer
   */
  protected $ccn;

  /**
   * @var string
   */
  protected $name;

  /**
   * @var string
   */
  protected $signature;

  /**
   * @return array
   */
  public function getArguments() {
    if ($this->arguments !== null) {
      return $this->arguments;
    }
    $this->arguments = array();
    $tokens = $this->tokenStream
      ->tokens();
    $typeDeclaration = null;

    // Search for first token inside brackets
    $i = $this->id + 2;
    while (!$tokens[$i - 1] instanceof PHP_Token_OPEN_BRACKET) {
      $i++;
    }
    while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
      if ($tokens[$i] instanceof PHP_Token_STRING) {
        $typeDeclaration = (string) $tokens[$i];
      }
      elseif ($tokens[$i] instanceof PHP_Token_VARIABLE) {
        $this->arguments[(string) $tokens[$i]] = $typeDeclaration;
        $typeDeclaration = null;
      }
      $i++;
    }
    return $this->arguments;
  }

  /**
   * @return string
   */
  public function getName() {
    if ($this->name !== null) {
      return $this->name;
    }
    $tokens = $this->tokenStream
      ->tokens();
    for ($i = $this->id + 1; $i < count($tokens); $i++) {
      if ($tokens[$i] instanceof PHP_Token_STRING) {
        $this->name = (string) $tokens[$i];
        break;
      }
      elseif ($tokens[$i] instanceof PHP_Token_AMPERSAND && $tokens[$i + 1] instanceof PHP_Token_STRING) {
        $this->name = (string) $tokens[$i + 1];
        break;
      }
      elseif ($tokens[$i] instanceof PHP_Token_OPEN_BRACKET) {
        $this->name = 'anonymous function';
        break;
      }
    }
    if ($this->name != 'anonymous function') {
      for ($i = $this->id; $i; --$i) {
        if ($tokens[$i] instanceof PHP_Token_NAMESPACE) {
          $this->name = $tokens[$i]
            ->getName() . '\\' . $this->name;
          break;
        }
        if ($tokens[$i] instanceof PHP_Token_INTERFACE) {
          break;
        }
      }
    }
    return $this->name;
  }

  /**
   * @return integer
   */
  public function getCCN() {
    if ($this->ccn !== null) {
      return $this->ccn;
    }
    $this->ccn = 1;
    $end = $this
      ->getEndTokenId();
    $tokens = $this->tokenStream
      ->tokens();
    for ($i = $this->id; $i <= $end; $i++) {
      switch (get_class($tokens[$i])) {
        case 'PHP_Token_IF':
        case 'PHP_Token_ELSEIF':
        case 'PHP_Token_FOR':
        case 'PHP_Token_FOREACH':
        case 'PHP_Token_WHILE':
        case 'PHP_Token_CASE':
        case 'PHP_Token_CATCH':
        case 'PHP_Token_BOOLEAN_AND':
        case 'PHP_Token_LOGICAL_AND':
        case 'PHP_Token_BOOLEAN_OR':
        case 'PHP_Token_LOGICAL_OR':
        case 'PHP_Token_QUESTION_MARK':
          $this->ccn++;
          break;
      }
    }
    return $this->ccn;
  }

  /**
   * @return string
   */
  public function getSignature() {
    if ($this->signature !== null) {
      return $this->signature;
    }
    if ($this
      ->getName() == 'anonymous function') {
      $this->signature = 'anonymous function';
      $i = $this->id + 1;
    }
    else {
      $this->signature = '';
      $i = $this->id + 2;
    }
    $tokens = $this->tokenStream
      ->tokens();
    while (isset($tokens[$i]) && !$tokens[$i] instanceof PHP_Token_OPEN_CURLY && !$tokens[$i] instanceof PHP_Token_SEMICOLON) {
      $this->signature .= $tokens[$i++];
    }
    $this->signature = trim($this->signature);
    return $this->signature;
  }

}

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_FUNCTION::$arguments protected property
PHP_Token_FUNCTION::$ccn protected property
PHP_Token_FUNCTION::$name protected property
PHP_Token_FUNCTION::$signature protected property
PHP_Token_FUNCTION::getArguments public function
PHP_Token_FUNCTION::getCCN public function
PHP_Token_FUNCTION::getName public function
PHP_Token_FUNCTION::getSignature public function