/** * @param float $minPrice * @param float $maxPrice */ public function __construct($minPrice = 0.0, $maxPrice = 0.0) { Assertion::numeric($minPrice); Assertion::numeric($maxPrice); $this->minPrice = (double) $minPrice; $this->maxPrice = (double) $maxPrice; }
/** * @param float $zValue * @param float $deviation */ public function __construct($zValue, $deviation) { Assertion::numeric($zValue, 'Z-value was not numeric, got "%s"'); Assertion::numeric($deviation, 'Deviation was not numeric, got "%s"'); $this->zValue = (double) $zValue; $this->deviation = (double) $deviation; }
public function set($tag_name, $value) { switch ($tag_name) { case self::LONGITUDE_TAG_NAME: Assertion::numeric($value); $this->longitude = (double) $value; break; case self::LATITUDE_TAG_NAME: Assertion::numeric($value); $this->latitude = (double) $value; break; case self::LONGITUDE_REF_TAG_NAME: $normalized = strtoupper($value); if ($normalized !== self::LONGITUDE_REF_EAST && $normalized !== self::LONGITUDE_REF_WEST) { throw new \InvalidArgumentException(sprintf('Invalid longitude reference "%s" (expecting "%s" or "%s").', $value, self::LONGITUDE_REF_EAST, self::LONGITUDE_REF_WEST)); } $this->longitude_ref = $value; break; case self::LATITUDE_REF_TAG_NAME: $normalized = strtoupper($value); if ($normalized !== self::LATITUDE_REF_NORTH && $normalized !== self::LATITUDE_REF_SOUTH) { throw new \InvalidArgumentException(sprintf('Invalid latitude reference "%s" (expecting "%s" or "%s").', $value, self::LATITUDE_REF_NORTH, self::LATITUDE_REF_SOUTH)); } $this->latitude_ref = $normalized; break; default: throw new \InvalidArgumentException(sprintf('Unsupported tag name "%s".', $tag_name)); } }
/** * @param string $name * @param numeric $price * @param integer $quantity * @param mixed $id */ public function __construct($name, $price, $quantity, $id = null) { Assertion::numeric($price); $this->setQuantity($quantity); $this->name = $name; $this->price = $price; $this->id = $id; }
public function __invoke($value) : ValidationResult { Assertion::numeric($value); $decimalValue = Decimal::fromString((string) $value); if ($decimalValue->comp($this->limit) === 1) { return new ValidationResult(new ValidationError('error.max-number', ['limit' => (string) $this->limit])); } return new ValidationResult(); }
public function __construct($value) { try { Assertion::numeric($value); $this->value = $value + 0; } catch (AssertionInvalidArgumentException $exception) { throw new InvalidArgumentException($value, array('number')); } }
public function __construct($value) { try { Assertion::numeric($value); $this->value = filter_var($value, FILTER_VALIDATE_FLOAT); } catch (AssertionInvalidArgumentException $exception) { throw new InvalidArgumentException($value, array('float')); } }
public function __invoke($value) : ValidationResult { Assertion::numeric($value); $decimalValue = Decimal::fromString((string) $value); $floorModulo = $this->floorModulo($decimalValue->sub($this->base), $this->step); if ($floorModulo->comp(DecimalConstants::zero()) !== 0) { return new ValidationResult(new ValidationError('error.step-number', ['lowValue' => $this->trimZeroDecimal((string) $decimalValue->sub($floorModulo)), 'highValue' => $this->trimZeroDecimal((string) $decimalValue->add($this->step)->sub($floorModulo))])); } return new ValidationResult(); }
/** * Retrieves exchange rates from http://fixer.io * * @param Currency $currency */ private function retrieveExchangeRateFor(Currency $currency) { $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/latest', ['query' => ['base' => $this->baseCurrency->getName()]]); Assert::same($response->getStatusCode(), 200); $rawExchangeRates = $response->getBody(); $exchangeRates = json_decode($rawExchangeRates, true); Assert::isArray($exchangeRates); Assert::keyExists($exchangeRates, 'rates'); Assert::keyExists($exchangeRates['rates'], $currency->getName()); Assert::numeric($exchangeRates['rates'][$currency->getName()]); $this->exchangeRates[$currency->getName()] = $exchangeRates['rates'][$currency->getName()]; }
/** * Retrieves exchange rates from http://free.currencyconverterapi.com * * @param Currency $currency */ private function retrieveExchangeRateFor(Currency $currency) { $conversion = sprintf('%s_%s', $currency->getName(), $this->baseCurrency->getName()); $response = $this->client->request('GET', self::EXCHANGE_RATE_API_URL . '/api/v3/convert', ['query' => ['q' => $conversion]]); Assert::same($response->getStatusCode(), 200); $rawExchangeRates = $response->getBody(); $exchangeRates = json_decode($rawExchangeRates, true); Assert::isArray($exchangeRates); Assert::keyExists($exchangeRates, 'results'); Assert::keyExists($exchangeRates['results'], $conversion); Assert::keyExists($exchangeRates['results'][$conversion], 'val'); Assert::numeric($exchangeRates['results'][$conversion]['val']); $this->exchangeRates[$currency->getName()] = (double) $exchangeRates['results'][$conversion]['val']; }
/** * @param float $rating * * @throws \InvalidArgumentException * * @return static */ public function withRating($rating) { Assertion::numeric($rating); Assertion::greaterOrEqualThan($rating, VideoInterface::RATING_MIN); Assertion::lessOrEqualThan($rating, VideoInterface::RATING_MAX); $instance = clone $this; $instance->rating = $rating; return $instance; }
public function testValidNumeric() { Assertion::numeric("1"); Assertion::numeric(1); Assertion::numeric(1.23); }
/** * @param float $average */ public function __construct($average) { Assertion::numeric($average); $this->average = (double) $average; }
/** * @param float $price */ public function setPrice($price) { Assertion::notNull($price); Assertion::numeric($price); $this->price = $price; }
/** * @param float $discountedPrice */ private function setDiscountedPrice($discountedPrice) { Assertion::numeric($discountedPrice, 'Discounted price should be numeric'); $this->discountedPrice = (double) $discountedPrice; }
/** * Validate price: * 0 < $price < 10000 * @param $price */ public static function price($price) { Assert::numeric($price); Assert::greaterThan($price, 0); Assert::lessThan($price, 10000); }
/** * {@inheritdoc} */ public function unbind(string $key, $value) : Data { Assertion::string($value); Assertion::numeric($value); return Data::fromFlatArray([$key => $value]); }
/** * Create a new AnyNumber * * @param int $value * @return void */ public function __construct($value) { Assertion::numeric($value); $this->value = $value; }
public function notifyAmountTries() { Assertion::numeric($this->maxTries, "The property doesn't have an integer as value"); return $this->maxTries; }
/** * Defines the amount of entities to be fetched from the information provider. * * @param integer $limit Positive integer defining the amount of records to be return in max. Zero (0) defines an unlimited amount. * * @throws \Assert\InvalidArgumentException in case the provided argument does not meet expectations. */ public function setLimit($limit) { $message = 'Given limit must be a positive number.'; Assertion::numeric($limit, $message); Assertion::min($limit, 0, $message); $this->limit = $limit; }