You are here

class TypeToken in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php \Prophecy\Argument\Token\TypeToken

Value type token.

@author Konstantin Kudryashov <ever.zet@gmail.com>

Hierarchy

Expanded class hierarchy of TypeToken

File

vendor/phpspec/prophecy/src/Prophecy/Argument/Token/TypeToken.php, line 21

Namespace

Prophecy\Argument\Token
View source
class TypeToken implements TokenInterface {
  private $type;

  /**
   * @param string $type
   */
  public function __construct($type) {
    $checker = "is_{$type}";
    if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) {
      throw new InvalidArgumentException(sprintf('Type or class name expected as an argument to TypeToken, but got %s.', $type));
    }
    $this->type = $type;
  }

  /**
   * Scores 5 if argument has the same type this token was constructed with.
   *
   * @param $argument
   *
   * @return bool|int
   */
  public function scoreArgument($argument) {
    $checker = "is_{$this->type}";
    if (function_exists($checker)) {
      return call_user_func($checker, $argument) ? 5 : false;
    }
    return $argument instanceof $this->type ? 5 : false;
  }

  /**
   * Returns false.
   *
   * @return bool
   */
  public function isLast() {
    return false;
  }

  /**
   * Returns string representation for token.
   *
   * @return string
   */
  public function __toString() {
    return sprintf('type(%s)', $this->type);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TypeToken::$type private property
TypeToken::isLast public function Returns false. Overrides TokenInterface::isLast
TypeToken::scoreArgument public function Scores 5 if argument has the same type this token was constructed with. Overrides TokenInterface::scoreArgument
TypeToken::__construct public function
TypeToken::__toString public function Returns string representation for token. Overrides TokenInterface::__toString