Skip to content

Instantly share code, notes, and snippets.

@srosato
Forked from gCardinal/gist:1d869c86c4bf4f7e7b90
Last active February 10, 2016 21:48
Show Gist options
  • Save srosato/a353b30a75af665579c9 to your computer and use it in GitHub Desktop.
Save srosato/a353b30a75af665579c9 to your computer and use it in GitHub Desktop.
<?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);
}
@srosato
Copy link
Author

srosato commented Feb 10, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment