OOP Checkpoint

OOP Checkpoint

Playground Checkpoint

Fix the booking desk's classes so every rule lives in the right class — the expected output tells you when it's right.

30–40 min

The Challenge

Monday morning, Olivia wants the new counter screen. Mia's first version has all the right classes — Service, Customer, Barber, Booking, a Notifier interface and a BookingDesk — but four bugs from this Act are hiding in them.

Open the starter in the PHP Playground with the button below and run it. It sends "REAL SMS" although a fake notifier was passed in, it sends twice on a double click, it lets a cancelled booking be confirmed again, and it charges £0.00. Fix the classes, not the counter-screen lines.

What You Need to Do

  • Run the starter and match each wrong line of output to a chapter of this Act.
  • Fix Booking::total() so it adds up the booking's own services (chapter 2).
  • Make BookingDesk use the notifier it's given, with constructor property promotion (chapters 3 and 12).
  • Make the booking's status private, so it can only change through confirm() and cancel() (chapter 4).
  • Put the rules in Booking: confirming a cancelled booking throws a LogicException with the message "A cancelled booking can't be confirmed", and confirming twice sends only one message (chapters 4 and 10).
  • Make Service an immutable value object (chapter 6).
  • Don't change the lines under "The counter screen". The output must match the expected output exactly, with no warnings and no "REAL SMS".
Stuck? A Few Hints
  • Inside a method, the booking's services are $this->services, not $services (chapter 2).
  • The BookingDesk constructor ignores its $notifier parameter. With promotion — private Notifier $notifier — there's nothing to forget (chapter 12).
  • Let Booking::confirm() return true only when the status really changed, and let BookingDesk send the message only then.
  • final readonly class Service needs no other change: its properties are already set in the constructor.

Ready to Build It?

Opens the Playground, right in your browser — nothing to install.

Open Playground

A correct run prints four lines and the message: the summary with £27.50 and "(confirmed)", "Refused: A cancelled booking can't be confirmed", "1 message(s) sent" and the one confirmation text to +447700900456 — no warnings and no "REAL SMS". The starter prints "REAL SMS" three times, a warning about $services, a total of £0.00, no refusal and "0 message(s) sent".

Before You Move On

If your output matches, BookBay's booking desk is built from objects that guard their own rules: the status can't be set to nonsense, prices can't change, and the notifier can be swapped for a fake. Along the way you've used every core OOP feature PHP has — and you know the ones it doesn't. Next: modern PHP OOP — enums for the status, property hooks, magic methods and attributes.