public function customMetric($metricName, $value) { Assertion::string($metricName); Assertion::notBlank($metricName); Assertion::float($value); return $this->handle('newrelic_custom_metric', [$metricName, $value]); }
/** * @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; }
public function toFileMakerValue($value) { if (null === $value) { return null; } Assertion::float($value); return Decimal::fromFloat($value); }
/** * @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; }
/** * 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; }
public function testValidFloat() { Assertion::float(1.0); Assertion::float(0.1); Assertion::float(-1.1); }
/** * @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; }
/** * Cosntructor * * @param string $value [optional] */ public function __construct($value = null) { Assertion::float($value); $this->value = $value; }
public function isFloat($value) { parent::float($value); }
/** * {@inheritdoc} */ public function unbind(string $key, $value) : Data { Assertion::float($value); return Data::fromFlatArray([$key => (string) $value]); }
/** * @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; }
/** * 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)); }