Chris@0: Chris@0: * Marcello Duarte Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Prophecy\Argument\Token; Chris@0: Chris@0: use Prophecy\Util\StringUtil; Chris@0: Chris@0: /** Chris@0: * Identical value token. Chris@0: * Chris@0: * @author Florian Voutzinos Chris@0: */ Chris@0: class IdenticalValueToken implements TokenInterface Chris@0: { Chris@0: private $value; Chris@0: private $string; Chris@0: private $util; Chris@0: Chris@0: /** Chris@0: * Initializes token. Chris@0: * Chris@0: * @param mixed $value Chris@0: * @param StringUtil $util Chris@0: */ Chris@0: public function __construct($value, StringUtil $util = null) Chris@0: { Chris@0: $this->value = $value; Chris@0: $this->util = $util ?: new StringUtil(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Scores 11 if argument matches preset value. Chris@0: * Chris@0: * @param $argument Chris@0: * Chris@0: * @return bool|int Chris@0: */ Chris@0: public function scoreArgument($argument) Chris@0: { Chris@0: return $argument === $this->value ? 11 : false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns false. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isLast() Chris@0: { Chris@0: return false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns string representation for token. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function __toString() Chris@0: { Chris@0: if (null === $this->string) { Chris@0: $this->string = sprintf('identical(%s)', $this->util->stringify($this->value)); Chris@0: } Chris@0: Chris@0: return $this->string; Chris@0: } Chris@0: }