/** * @param InformationUnit $unit * * @return InformationUnit * @throws \OutOfBoundsException */ public function subtract(InformationUnit $unit) : self { $value = self::convert($unit->getAmount(), $unit->getDimensionCode(), $this->getDimensionCode()); $result = $this->getAmount() - $value; if ($result < 0) { throw new \OutOfBoundsException('Cannot subtract, less or equal zero result'); } $this->amount = $result; return $this; }
/** * Bytes constructor. * * @param float $amount * * @throws \OutOfBoundsException */ public function __construct(float $amount) { parent::__construct($amount); $this->dimension = self::$megaByte; }