Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Taking coffee from the pot
- * If it's earlier than 11:00 and the process leaves an empty
- * pot, the pot is refilled.
- *
- * @param Pot $pot(, float $milk)
- * @return Cup $cup
- * @author Mikael Grön
- */
- function takeCoffeeFrom(Pot $pot, bool $milk = false) {
- // Figure out how much coffee can be used
- $amount = MAX($pot->amount, Cup::size);
- // Create a cup with the correct amount of coffee
- $cup = new Cup($amount);
- // Add milk, if appropriate
- if ($milk) {
- $cup->addMilk();
- }
- // Modify the remaining amount of coffee in the pot
- $pot->removeCoffee($amount);
- // Refill the pot if it's empty and it's before 11 in the day.
- if ($pot->amount == Cup::size
- && (
- time() <= strtotime(date('Y-m-d')." 11:00")
- || time() >= strtotime(date('Y-m-d'." 12:30")
- )
- && time() >= strtotime(date('Y-m-d'). " 07:00")
- && time() <= strtotime(date('Y-m-d'). " 15:00")
- )) {
- $pot->refill();
- }
- return $cup;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement