You are here

class CallbackToken in Zircon Profile 8

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

Callback-verified token.

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

Hierarchy

Expanded class hierarchy of CallbackToken

File

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

Namespace

Prophecy\Argument\Token
View source
class CallbackToken implements TokenInterface {
  private $callback;

  /**
   * Initializes token.
   *
   * @param callable $callback
   *
   * @throws \Prophecy\Exception\InvalidArgumentException
   */
  public function __construct($callback) {
    if (!is_callable($callback)) {
      throw new InvalidArgumentException(sprintf('Callable expected as an argument to CallbackToken, but got %s.', gettype($callback)));
    }
    $this->callback = $callback;
  }

  /**
   * Scores 7 if callback returns true, false otherwise.
   *
   * @param $argument
   *
   * @return bool|int
   */
  public function scoreArgument($argument) {
    return call_user_func($this->callback, $argument) ? 7 : false;
  }

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

  /**
   * Returns string representation for token.
   *
   * @return string
   */
  public function __toString() {
    return 'callback()';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CallbackToken::$callback private property
CallbackToken::isLast public function Returns false. Overrides TokenInterface::isLast
CallbackToken::scoreArgument public function Scores 7 if callback returns true, false otherwise. Overrides TokenInterface::scoreArgument
CallbackToken::__construct public function Initializes token.
CallbackToken::__toString public function Returns string representation for token. Overrides TokenInterface::__toString