Skip to content

Instantly share code, notes, and snippets.

@gander
Last active December 3, 2020 11:59
Show Gist options
  • Save gander/d5743a291bf55a8f89660372152922b7 to your computer and use it in GitHub Desktop.
Save gander/d5743a291bf55a8f89660372152922b7 to your computer and use it in GitHub Desktop.
Scary code showing how not to code. Found in production
<?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