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;
19 * @author Konstantin Kudryashov <ever.zet@gmail.com>
21 class TypeToken implements TokenInterface
28 public function __construct($type)
30 $checker = "is_{$type}";
31 if (!function_exists($checker) && !interface_exists($type) && !class_exists($type)) {
32 throw new InvalidArgumentException(sprintf(
33 'Type or class name expected as an argument to TypeToken, but got %s.', $type
41 * Scores 5 if argument has the same type this token was constructed with.
47 public function scoreArgument($argument)
49 $checker = "is_{$this->type}";
50 if (function_exists($checker)) {
51 return call_user_func($checker, $argument) ? 5 : false;
54 return $argument instanceof $this->type ? 5 : false;
62 public function isLast()
68 * Returns string representation for token.
72 public function __toString()
74 return sprintf('type(%s)', $this->type);