How can the PHP code be refactored to improve readability and maintainability?

The PHP code can be refactored by breaking down the long and complex logic into smaller, more manageable functions. This will improve readability and maintainability by making the code easier to understand and modify in the future.

function checkIfUserIsAdmin($user) {
    // Check if the user is an admin
    return $user->role === 'admin';
}

function processUserAccess($user) {
    if (checkIfUserIsAdmin($user)) {
        // Process admin access
    } else {
        // Process regular user access
    }
}

$user = getUserById($userId);
processUserAccess($user);