/** * Returns the value of type * * @param boolean $filter If false, the given types will be filtered out * * @return Money */ public function getValueOfType($price, Type $type, $filter = true) { if ($price instanceof Money === false) { throw new InvalidArgumentException('The given value is not a valid Money object.'); } $total = new Money(0, $price->getCurrency()); foreach ($this->data as $option) { $value = $option->getValue($price); $price = $price->add($value); if ($type->validate($option) === (bool) $filter) { $total = $total->add($value); } } return $total; }
/** * Validates one value * * @param mixed $value */ public function validateOne($value) { if ($this->type->validate($value) === false) { throw new InvalidArgumentException($this->type->getMessage()); } }