Last active
October 8, 2017 03:13
-
-
Save buiquangduc/5ea67037b67ac2b24b72d2a014f03b8e to your computer and use it in GitHub Desktop.
Routine simplify complicated boolean tests
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 | |
$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