4 * This file is part of the Prophecy.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6 * Marcello Duarte <marcello.duarte@gmail.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Prophecy\Argument\Token;
14 use Prophecy\Exception\InvalidArgumentException;
17 * Callback-verified token.
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class CallbackToken implements TokenInterface
28 * @param callable $callback
30 * @throws \Prophecy\Exception\InvalidArgumentException
32 public function __construct($callback)
34 if (!is_callable($callback)) {
35 throw new InvalidArgumentException(sprintf(
36 'Callable expected as an argument to CallbackToken, but got %s.',
41 $this->callback = $callback;
45 * Scores 7 if callback returns true, false otherwise.
51 public function scoreArgument($argument)
53 return call_user_func($this->callback, $argument) ? 7 : false;
61 public function isLast()
67 * Returns string representation for token.
71 public function __toString()