How can the admin_check() function be refactored to improve readability and maintainability in PHP code?
The admin_check() function can be refactored by breaking it down into smaller, more focused functions with descriptive names. This will improve readability and maintainability by making the code easier to understand and modify in the future.
// Refactored admin_check() function
function is_admin($user) {
return $user['role'] === 'admin';
}
function is_valid_user($user) {
return isset($user['id']) && isset($user['name']);
}
function admin_check($user) {
if (is_valid_user($user) && is_admin($user)) {
return true;
}
return false;
}