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 14/** 15 * Approximate value token 16 * 17 * @author Daniel Leech <daniel@dantleech.com> 18 */ 19class ApproximateValueToken implements TokenInterface 20{ 21 private $value; 22 private $precision; 23 24 public function __construct($value, $precision = 0) 25 { 26 $this->value = $value; 27 $this->precision = $precision; 28 } 29 30 /** 31 * {@inheritdoc} 32 */ 33 public function scoreArgument($argument) 34 { 35 return round($argument, $this->precision) === round($this->value, $this->precision) ? 10 : false; 36 } 37 38 /** 39 * {@inheritdoc} 40 */ 41 public function isLast() 42 { 43 return false; 44 } 45 46 /** 47 * Returns string representation for token. 48 * 49 * @return string 50 */ 51 public function __toString() 52 { 53 return sprintf('≅%s', round($this->value, $this->precision)); 54 } 55} 56