Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buiquangduc/5ea67037b67ac2b24b72d2a014f03b8e to your computer and use it in GitHub Desktop.
Save buiquangduc/5ea67037b67ac2b24b72d2a014f03b8e to your computer and use it in GitHub Desktop.
Routine simplify complicated boolean tests
<?php
$person = new Person(1) // Get the person with ID=1
// In this example we will check if the person's fullname is too long or not
// Replace these bunch of code
$fullName = getFullname($person);
if(strlen($fullName) > 20) {
$isFullnameTooLong = true;
} else {
$isFullnameTooLong = false;
}
if($isFullnameTooLong) {
// Actions when full name is too long
}
// With
if(isTooLong($fullName)) {
// Actions when full name is too long
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment