Beispiel #1
0
 /**
  * @param Capacity $capacity
  * @throws GlassCapacityOverflowException
  * @throws GlassIsAlreadyOnFireException
  */
 public function pourIn(Capacity $capacity)
 {
     if ($this->isOnFire()) {
         throw new GlassIsAlreadyOnFireException();
     }
     if (!$this->canPourIn($capacity)) {
         throw new GlassCapacityOverflowException();
     }
     if (is_null($this->currentCapacity)) {
         $this->currentCapacity = $capacity;
         return;
     }
     if ($capacity->getMilliliters() + $this->currentCapacity->getMilliliters() > $this->getTotalCapacity()->getMilliliters()) {
         throw new GlassCapacityOverflowException();
     }
     $this->currentCapacity = $this->currentCapacity->add($capacity);
     $this->stirred = false;
     $this->muddled = false;
 }
Beispiel #2
0
 /**
  * @param Capacity $capacity
  * @return Capacity
  */
 public function subtract(Capacity $capacity)
 {
     return new Capacity($this->milliliters - $capacity->getMilliliters());
 }
Beispiel #3
0
 /**
  * @param Capacity $capacity
  * @return Liquid
  */
 public function fill(Capacity $capacity)
 {
     return new Liquid($this->name, $this->capacity->add($capacity));
 }
Beispiel #4
0
 /**
  * @return Capacity
  */
 public function getAvailableCapacity()
 {
     return new Capacity($this->capacity->getMilliliters() - $this->currentCapacity->getMilliliters());
 }