Forked from gCardinal/gist:1d869c86c4bf4f7e7b90
Last active
February 10, 2016 21:48
-
-
Save srosato/a353b30a75af665579c9 to your computer and use it in GitHub Desktop.
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 | |
// Nous vérifions que l'utilisateur est bien du bon type pour ne pas appeler getLastActivity() sur un objet autre objet User | |
if ($user instanceof User && $user->getLastActivity() < $delay) { | |
$user->setActiveNow(); | |
$this->em->flush($user); | |
} | |
if ($user instanceof User && $user->getLastActivity() < $delay) { | |
$user->setActiveNow(); | |
$this->em->flush($user); | |
} | |
// CLEAN CODE APPROACH | |
private function isUserLastActivityBeforeDelay(User $user, $delay) { | |
return $user->getLastActivity() < $delay; | |
} | |
if( $this->isUserActivityBeforeDelay($user, $delay) ) { | |
$user->setActiveNow(); | |
$this->em->flush($user); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We do not need to use instance of because of the strong typing within the function arguments (User $user). PHP will throw an error if we do not pass the right interface.