public function DeductUnits(BuildGroup $bg) { Helper::containsNegative($bg->Members()); // You can't deduct negative units, of course if (!($this->Type() === $bg->Type() || $bg->Type() === "EMPTY" || $this->Type() === "EMPTY")) { throw new Exception("You can't combine different types of BuildGroups!"); } $otherList =& $bg->Members(); foreach ($this->Members() as $index => $buildItem) { if (isset($otherList[$index])) { $buildItem->Amount($buildItem->Amount() - $otherList[$index]->Amount()); } } Helper::containsNegative($this->Members()); // You can't deduct more than is present, of course }