numeric() публичный статический Метод

Assert that value is numeric.
public static numeric ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
Результат boolean
Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * @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;
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
 /**
  * @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;
 }
Пример #5
0
 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();
 }
Пример #6
0
 public function __construct($value)
 {
     try {
         Assertion::numeric($value);
         $this->value = $value + 0;
     } catch (AssertionInvalidArgumentException $exception) {
         throw new InvalidArgumentException($value, array('number'));
     }
 }
Пример #7
0
 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'));
     }
 }
Пример #8
0
 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'];
 }
Пример #11
0
 /**
  * @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;
 }
Пример #12
0
 public function testValidNumeric()
 {
     Assertion::numeric("1");
     Assertion::numeric(1);
     Assertion::numeric(1.23);
 }
Пример #13
0
 /**
  * @param float $average
  */
 public function __construct($average)
 {
     Assertion::numeric($average);
     $this->average = (double) $average;
 }
Пример #14
0
 /**
  * @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;
 }
Пример #16
0
 /**
  * Validate price:
  * 0 < $price < 10000
  * @param $price
  */
 public static function price($price)
 {
     Assert::numeric($price);
     Assert::greaterThan($price, 0);
     Assert::lessThan($price, 10000);
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function unbind(string $key, $value) : Data
 {
     Assertion::string($value);
     Assertion::numeric($value);
     return Data::fromFlatArray([$key => $value]);
 }
Пример #18
0
 /**
  * Create a new AnyNumber
  *
  * @param int $value
  * @return void
  */
 public function __construct($value)
 {
     Assertion::numeric($value);
     $this->value = $value;
 }
Пример #19
0
 public function notifyAmountTries()
 {
     Assertion::numeric($this->maxTries, "The property doesn't have an integer as value");
     return $this->maxTries;
 }
Пример #20
0
 /**
  * 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;
 }