You are here

public function TaxRate::__construct in Commerce Core 8.2

Constructs a new TaxRate instance.

Parameters

array $definition: The definition.

File

modules/tax/src/TaxRate.php, line 46

Class

TaxRate
Represents a tax rate.

Namespace

Drupal\commerce_tax

Code

public function __construct(array $definition) {
  foreach ([
    'id',
    'label',
    'percentages',
  ] as $required_property) {
    if (empty($definition[$required_property])) {
      throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
    }
  }
  if (!is_array($definition['percentages'])) {
    throw new \InvalidArgumentException(sprintf('The property "percentages" must be an array.'));
  }
  $this->id = $definition['id'];
  $this->label = $definition['label'];
  foreach ($definition['percentages'] as $percentage_definition) {
    $this->percentages[] = new TaxRatePercentage($percentage_definition);
  }
  $this->default = !empty($definition['default']);
}