Advertisement
skaramicke

Coffee

May 11th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Taking coffee from the pot
  5.  * If it's earlier than 11:00 and the process leaves an empty
  6.  * pot, the pot is refilled.
  7.  *
  8.  * @param Pot $pot(, float $milk)
  9.  * @return Cup $cup
  10.  * @author Mikael Grön
  11.  */
  12. function takeCoffeeFrom(Pot $pot, bool $milk = false) {
  13.     // Figure out how much coffee can be used
  14.     $amount = MAX($pot->amount, Cup::size);
  15.  
  16.     // Create a cup with the correct amount of coffee
  17.     $cup = new Cup($amount);
  18.    
  19.     // Add milk, if appropriate
  20.     if ($milk) {
  21.         $cup->addMilk();
  22.     }
  23.    
  24.     // Modify the remaining amount of coffee in the pot
  25.     $pot->removeCoffee($amount);
  26.    
  27.     // Refill the pot if it's empty and it's before 11 in the day.
  28.     if ($pot->amount == Cup::size
  29.         && (
  30.             time() <= strtotime(date('Y-m-d')." 11:00")
  31.             || time() >= strtotime(date('Y-m-d'." 12:30")
  32.         )
  33.         && time() >= strtotime(date('Y-m-d'). " 07:00")
  34.         && time() <= strtotime(date('Y-m-d'). " 15:00")
  35.         )) {
  36.         $pot->refill();
  37.     }
  38.    
  39.     return $cup;
  40. }
  41.    
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement