1<?php 2 3/* 4 * This file is part of the Prophecy. 5 * (c) Konstantin Kudryashov <ever.zet@gmail.com> 6 * Marcello Duarte <marcello.duarte@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Prophecy\Argument\Token; 13 14use Prophecy\Util\StringUtil; 15 16/** 17 * Identical value token. 18 * 19 * @author Florian Voutzinos <florian@voutzinos.com> 20 */ 21class IdenticalValueToken implements TokenInterface 22{ 23 private $value; 24 private $string; 25 private $util; 26 27 /** 28 * Initializes token. 29 * 30 * @param mixed $value 31 * @param StringUtil $util 32 */ 33 public function __construct($value, StringUtil $util = null) 34 { 35 $this->value = $value; 36 $this->util = $util ?: new StringUtil(); 37 } 38 39 /** 40 * Scores 11 if argument matches preset value. 41 * 42 * @param $argument 43 * 44 * @return bool|int 45 */ 46 public function scoreArgument($argument) 47 { 48 return $argument === $this->value ? 11 : false; 49 } 50 51 /** 52 * Returns false. 53 * 54 * @return bool 55 */ 56 public function isLast() 57 { 58 return false; 59 } 60 61 /** 62 * Returns string representation for token. 63 * 64 * @return string 65 */ 66 public function __toString() 67 { 68 if (null === $this->string) { 69 $this->string = sprintf('identical(%s)', $this->util->stringify($this->value)); 70 } 71 72 return $this->string; 73 } 74} 75