SOFTWARE ENGINEERING/Art Of Readable Code
Ch12 Turning Thoughts into Code
파란실버라이트
2012. 11. 23. 13:01
1.Describing Logic Clearly
$is_admin = is_admin_request();
if ($document) {
if (!$is_admin && ($document['username'] != $_SESSION['username'])) {
return not_authorized();
}
} else {
if (!$is_admin) {
return not_authorized();
}
}
// continue rendering the page ...
//Here is an alternative solution inspired by this description:
if (is_admin_request()) {
// authorized
} elseif ($document && ($document['username'] == $_SESSION['username'])) {
// authorized
} else {
return not_authorized();
}
// continue rendering the page ...