class ApproximateValueToken
Approximate value token
@author Daniel Leech <daniel@dantleech.com>
Hierarchy
- class \Prophecy\Argument\Token\ApproximateValueToken implements \Prophecy\Argument\Token\TokenInterface
Expanded class hierarchy of ApproximateValueToken
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ ApproximateValueToken.php, line 19
Namespace
Prophecy\Argument\TokenView source
class ApproximateValueToken implements TokenInterface {
private $value;
private $precision;
/**
* @param float $value
* @param int $precision
*/
public function __construct($value, $precision = 0) {
$this->value = $value;
$this->precision = $precision;
}
/**
* {@inheritdoc}
*/
public function scoreArgument($argument) {
if (!\is_float($argument) && !\is_int($argument) && !\is_numeric($argument)) {
return false;
}
return round((double) $argument, $this->precision) === round($this->value, $this->precision) ? 10 : false;
}
/**
* {@inheritdoc}
*/
public function isLast() {
return false;
}
/**
* Returns string representation for token.
*
* @return string
*/
public function __toString() {
return sprintf('≅%s', round($this->value, $this->precision));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ApproximateValueToken::$precision | private | property | ||
ApproximateValueToken::$value | private | property | ||
ApproximateValueToken::isLast | public | function | Returns true if this token prevents check of other tokens (is last one). | Overrides TokenInterface::isLast |
ApproximateValueToken::scoreArgument | public | function | Calculates token match score for provided argument. | Overrides TokenInterface::scoreArgument |
ApproximateValueToken::__construct | public | function | ||
ApproximateValueToken::__toString | public | function | Returns string representation for token. | Overrides TokenInterface::__toString |