Don’t rely entity setters (order)
What this code does?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
class DateTimeInterval { private $from; private $to; private $allDayLong; public function setFrom(\DateTime $from) { if ($this->isAllDayLong()) { $from->setTime(0, 0, 0); } $this->from = $from; return $this; } public function getFrom() { ... } // omitted public function setTo(\DateTime $to) { if ($this->isAllDayLong()) { $to->setTime(23, 59, 59); } $this->to = $to; return $this; } public function getTo() { ... } // omitted public function allDayLong() { $this->allDayLong = true; } public function isAllDayLong() { return $this->allDayLong; } } |
It’s a simple class that represent a DateTimeInterval with a flag named allDayLong that let an object of DateTimeInterval class to fill all day. You can see that…