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: /** Chris@0: * Approximate value token Chris@0: * Chris@0: * @author Daniel Leech Chris@0: */ Chris@0: class ApproximateValueToken implements TokenInterface Chris@0: { Chris@0: private $value; Chris@0: private $precision; Chris@0: Chris@0: public function __construct($value, $precision = 0) Chris@0: { Chris@0: $this->value = $value; Chris@0: $this->precision = $precision; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function scoreArgument($argument) Chris@0: { Chris@0: return round($argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} 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: return sprintf('≅%s', round($this->value, $this->precision)); Chris@0: } Chris@0: }