You are here

public function TaxRatePercentage::__construct in Commerce Core 8.2

Constructs a new TaxRatePercentage instance.

Parameters

array $definition: The definition.

File

modules/tax/src/TaxRatePercentage.php, line 41

Class

TaxRatePercentage
Represents a tax rate percentage.

Namespace

Drupal\commerce_tax

Code

public function __construct(array $definition) {
  foreach ([
    'number',
    'start_date',
  ] as $required_property) {
    if (!isset($definition[$required_property]) || $definition[$required_property] === '') {
      throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
    }
  }
  if (is_float($definition['number'])) {
    throw new \InvalidArgumentException(sprintf('The provided number "%s" must be a string, not a float.', $definition['number']));
  }
  if (!is_numeric($definition['number'])) {
    throw new \InvalidArgumentException(sprintf('The provided number "%s" is not a numeric value.', $definition['number']));
  }
  $this->number = $definition['number'];
  $this->startDate = $definition['start_date'];
  $this->endDate = !empty($definition['end_date']) ? $definition['end_date'] : NULL;
}