Last active
December 3, 2020 11:59
-
-
Save gander/d5743a291bf55a8f89660372152922b7 to your computer and use it in GitHub Desktop.
Scary code showing how not to code. Found in production
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DateFixer { | |
public function fix(string $date): string { | |
$time = new DateTime($date); | |
$time->modify('+3 days'); | |
return $time->format('Y-m-d'); | |
} | |
} | |
// Doctrine | |
$entity = $entityManager->find(Order::class, 123); | |
$date = $entity->getShipmentDate()->format('Y-m-d'); | |
$date = DateFixer::fix($date); | |
$entity->setShipmentDate(new DateTime($date)); | |
$entityManager->persist($entity); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment