float() public static method

Assert that value is a php float.
public static float ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
Exemplo n.º 1
0
 public function customMetric($metricName, $value)
 {
     Assertion::string($metricName);
     Assertion::notBlank($metricName);
     Assertion::float($value);
     return $this->handle('newrelic_custom_metric', [$metricName, $value]);
 }
Exemplo n.º 2
0
 /**
  * @param float  $value
  * @param string $currency
  *
  * @throws \InvalidArgumentException
  */
 public function __construct($value, $currency)
 {
     Assertion::float($value);
     Assertion::greaterOrEqualThan($value, PriceInterface::VALUE_MIN);
     $this->value = $value;
     $this->currency = $currency;
 }
 /**
  * Constructor.
  *
  * @param float $latitude The latitude.
  * @param float $longitude The longitude.
  */
 public function __construct($latitude, $longitude)
 {
     Assertion::float($latitude);
     Assertion::float($longitude);
     $this->latitude = $latitude;
     $this->longitude = $longitude;
 }
Exemplo n.º 4
0
 public function toFileMakerValue($value)
 {
     if (null === $value) {
         return null;
     }
     Assertion::float($value);
     return Decimal::fromFloat($value);
 }
Exemplo n.º 5
0
 /**
  * @param string $name
  * @param float $price
  * @param string $currency
  */
 public function __construct($name, $price, $currency)
 {
     Assertion::notEmpty($name);
     Assertion::float($price);
     Assertion::notEmpty($currency);
     $this->name = $name;
     $this->price = $price;
     $this->currency = $currency;
 }
Exemplo n.º 6
0
 /**
  * Constructor
  *
  * @param AMQPQueue $queue
  * @param float $idleTimeout in seconds
  * @param int $waitTimeout in microseconds
  * @param string|null $appId
  */
 public function __construct(AMQPQueue $queue, $idleTimeout, $waitTimeout, $appId = null)
 {
     Assertion::float($idleTimeout);
     Assertion::integer($waitTimeout);
     Assertion::nullOrString($appId);
     if (function_exists('pcntl_signal_dispatch')) {
         $this->usePcntlSignalDispatch = true;
     }
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, [$this, 'shutdown']);
         pcntl_signal(SIGINT, [$this, 'shutdown']);
         pcntl_signal(SIGHUP, [$this, 'shutdown']);
     }
     $this->blockSize = $queue->getChannel()->getPrefetchCount();
     $this->idleTimeout = (double) $idleTimeout;
     $this->waitTimeout = (int) $waitTimeout;
     $this->queues = new InfiniteIterator(new ArrayIterator([$queue]));
     $this->appId = $appId;
 }
Exemplo n.º 7
0
 public function testValidFloat()
 {
     Assertion::float(1.0);
     Assertion::float(0.1);
     Assertion::float(-1.1);
 }
Exemplo n.º 8
0
 /**
  * @param Envelope $envelope
  * @return DeliveryResult
  */
 protected function handleInternalMessage(Envelope $envelope) : DeliveryResult
 {
     if ('shutdown' === $envelope->getType()) {
         $this->logger->info('Shutdown message received');
         $this->shutdown();
         $result = DeliveryResult::MSG_ACK();
     } elseif ('reconfigure' === $envelope->getType()) {
         $this->logger->info('Reconfigure message received');
         try {
             list($idleTimeout, $target, $prefetchSize, $prefetchCount) = json_decode($envelope->getBody());
             if (is_numeric($idleTimeout)) {
                 $idleTimeout = (double) $idleTimeout;
             }
             Assertion::float($idleTimeout);
             Assertion::min($target, 0);
             Assertion::min($prefetchSize, 0);
             Assertion::min($prefetchCount, 0);
         } catch (\Throwable $e) {
             $this->logger->error('Exception during reconfiguration: ' . $e->getMessage());
             return DeliveryResult::MSG_REJECT();
         }
         $this->idleTimeout = $idleTimeout;
         $this->target = $target;
         $this->queue->getChannel()->qos($prefetchSize, $prefetchCount);
         $this->blockSize = $prefetchCount;
         $result = DeliveryResult::MSG_ACK();
     } elseif ('ping' === $envelope->getType()) {
         $this->logger->info('Ping message received');
         $result = DeliveryResult::MSG_ACK();
     } else {
         $this->logger->error('Invalid internal message: ' . $envelope->getType());
         $result = DeliveryResult::MSG_REJECT();
     }
     return $result;
 }
 /**
  * @param float $param
  */
 public function applyDiscount($param)
 {
     Assertion::float($param);
     $this->price = (double) $this->price * $param;
 }
Exemplo n.º 10
0
 /**
  * Cosntructor
  * 
  * @param string $value [optional]
  */
 public function __construct($value = null)
 {
     Assertion::float($value);
     $this->value = $value;
 }
Exemplo n.º 11
0
 public function isFloat($value)
 {
     parent::float($value);
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function unbind(string $key, $value) : Data
 {
     Assertion::float($value);
     return Data::fromFlatArray([$key => (string) $value]);
 }
Exemplo n.º 13
0
 /**
  * @param float $priority
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withPriority($priority)
 {
     Assertion::float($priority);
     Assertion::greaterOrEqualThan($priority, UrlInterface::PRIORITY_MIN);
     Assertion::lessOrEqualThan($priority, UrlInterface::PRIORITY_MAX);
     Assertion::same($priority, round($priority, 1));
     $instance = clone $this;
     $instance->priority = $priority;
     return $instance;
 }
Exemplo n.º 14
-1
 /**
  * Constructor
  *
  * @param AMQPQueue[] $queues
  * @param float $idleTimeout in seconds
  * @param int $waitTimeout in microseconds
  * @param callable $deliveryCallback,
  * @param callable|null $flushCallback,
  * @param callable|null $errorCallback
  * @throws Exception\InvalidArgumentException
  */
 public function __construct(array $queues, $idleTimeout, $waitTimeout, callable $deliveryCallback, callable $flushCallback = null, callable $errorCallback = null)
 {
     Assertion::float($idleTimeout);
     Assertion::integer($waitTimeout);
     if (function_exists('pcntl_signal_dispatch')) {
         $this->usePcntlSignalDispatch = true;
     }
     if (function_exists('pcntl_signal')) {
         pcntl_signal(SIGTERM, [$this, 'shutdown']);
         pcntl_signal(SIGINT, [$this, 'shutdown']);
         pcntl_signal(SIGHUP, [$this, 'shutdown']);
     }
     if (empty($queues)) {
         throw new Exception\InvalidArgumentException('No queues given');
     }
     $q = [];
     foreach ($queues as $queue) {
         if (!$queue instanceof AMQPQueue) {
             throw new Exception\InvalidArgumentException('Queue must be an instance of AMQPQueue, ' . is_object($queue) ? get_class($queue) : gettype($queue) . ' given');
         }
         if (null === $this->blockSize) {
             $this->blockSize = $queue->getChannel()->getPrefetchCount();
         }
         $q[] = $queue;
     }
     $this->idleTimeout = (double) $idleTimeout;
     $this->waitTimeout = (int) $waitTimeout;
     $this->queues = new InfiniteIterator(new ArrayIterator($q));
 }