Last active
July 14, 2018 11:49
-
-
Save amaelftah/96c0bb23ed9c934f8967eb5149fdf834 to your computer and use it in GitHub Desktop.
extracting conditions to meaningful functions
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 | |
if ( | |
$employee['age'] < '40' | |
&& $employee['medical_health'] == 'healthy' | |
&& $employee ['work_happits'] != 'bad' | |
) | |
{ | |
// do somethings | |
} | |
//what about if we extracted the condition to a meaningful function | |
if (canWork($employee)) | |
{ | |
//do something | |
} | |
function canWork($employee) | |
{ | |
return $employee['age'] < '40' | |
&& $employee['medical_health'] == 'healthy' | |
&& $employee ['work_happits'] != 'bad'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment