date_create = new DateTime(); $this->warranty_class = WarrantyClass::WTY_PRIVATE; $this->status = WarrantyStatus::ACTIVE; $this->date_claim = null; } public function getID() { return $this->id; } public function setSerial($serial) { $this->serial = $serial; return $this; } public function getSerial() { return $this->serial; } public function setWarrantyClass($class) { $this->warranty_class = $class; return $this; } public function getWarrantyClass() { return $this->warranty_class; } // TODO: use a service to handle plate number filtering public static function cleanPlateNumber($plate) { // trim and make upper case $clean_plate = strtoupper(trim($plate)); // remove invalid characters $clean_plate = preg_replace("/[^A-Z0-9]/", '', $clean_plate); // check for 4 to 5 digit diplomatic plate $res = preg_match("/^[0-9]{4,5}$/", $clean_plate); if ($res) return $clean_plate; // ABC-1234 or ABC-123 or ABC-12 format $res = preg_match("/^[A-Z]{3}[0-9]{2,4}$/", $clean_plate); if ($res) return $clean_plate; // AB-123 or AB-12345 or AB-1234 format (motorcycles) $res = preg_match("/^[A-Z]{2}[0-9]{3,5}$/", $clean_plate); if ($res) return $clean_plate; // 1234-AB format (motorcycles) $res = preg_match("/^[0-9]{4}[A-Z]{2}$/", $clean_plate); if ($res) return $clean_plate; return false; } public function setPlateNumber($plate) { // TODO: custom exception $plate_number = $this->cleanPlateNumber($plate); if (!$plate_number) throw new Exception('Invalid plate number.'); $this->plate_number = $plate_number; return $this; } public function getPlateNumber() { return $this->plate_number; } public function setBatteryModel(BatteryModel $model) { $this->bty_model = $model; return $this; } public function getBatteryModel() { return $this->bty_model; } public function setBatterySize(BatterySize $size) { $this->bty_size = $size; return $this; } public function getBatterySize() { return $this->bty_size; } public function setStatus($status) { $this->status = $status; return $this; } public function getStatus() { return $this->status; } public function getDateCreate() { return $this->date_create; } public function setDatePurchase(DateTime $date) { $this->date_purchase = $date; return $this; } public function getDatePurchase() { return $this->date_purchase; } public function setDateExpire(DateTime $date) { $this->date_expire = $date; return $this; } public function getDateExpire() { return $this->date_expire; } public function setDateClaim(DateTime $date = null) { $this->date_claim = $date; return $this; } public function getDateClaim() { return $this->date_claim; } public function canClaim() { if ($this->status == WarrantyStatus::ACTIVE) return true; if ($this->status == WarrantyStatus::CLAIMED) return true; return false; } }