You are here

public static function TemperatureUnit::assertExists in Physical Fields 8

Asserts that the given unit exists.

Parameters

string $unit: The unit.

Throws

\InvalidArgumentException

Overrides UnitInterface::assertExists

2 calls to TemperatureUnit::assertExists()
Temperature::convert in src/Temperature.php
Converts the current temperature measurement to a new unit.
TemperatureUnit::getBaseFactor in src/TemperatureUnit.php
Gets the base factor for the given unit.

File

src/TemperatureUnit.php, line 50

Class

TemperatureUnit
Provides common temperature units.

Namespace

Drupal\physical

Code

public static function assertExists($unit) {
  $allowed_units = [
    self::KELVIN,
    self::CELSIUS,
    self::FAHRENHEIT,
  ];
  if (!in_array($unit, $allowed_units)) {
    throw new \InvalidArgumentException(sprintf('Invalid temperature unit "%s" provided.', $unit));
  }
}