-
-
Save AhmedHelalAhmed/d6dc37493e158b9b3fc38cb79c8de258 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