Skip to content

Instantly share code, notes, and snippets.

@dorianneto
Last active January 19, 2018 20:49
Show Gist options
  • Save dorianneto/f594e949e183ce95276af85bca9493a8 to your computer and use it in GitHub Desktop.
Save dorianneto/f594e949e183ce95276af85bca9493a8 to your computer and use it in GitHub Desktop.
Post: Torne-se um ninja das funções com Early Return
<?php
public static function formatDate($date)
{
$format = DateTime::ATOM;
if ($date instanceof DateTime) {
$d = $date->format($format);
} elseif (is_numeric($date)) {
$d = date($format, $date);
} else {
$d = (string) $date;
}
return $d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment