Instantly share code, notes, and snippets.

Embed
What would you like to do?
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