Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ApproximateValueToken.php

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\Token
View 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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal