How can the principles of single responsibility and separation of concerns be applied to PHP classes, especially when dealing with user management?

To apply the principles of single responsibility and separation of concerns to PHP classes when dealing with user management, we can create separate classes for different responsibilities such as user authentication, user data manipulation, and user role management. Each class should have a specific and clearly defined purpose, making the code more modular, maintainable, and easier to understand.

class UserAuthentication {
    public function login($username, $password) {
        // Authentication logic here
    }

    public function logout() {
        // Logout logic here
    }
}

class UserData {
    public function getUserInfo($userId) {
        // Get user information logic here
    }

    public function updateUserEmail($userId, $newEmail) {
        // Update user email logic here
    }
}

class UserRoleManagement {
    public function assignRole($userId, $role) {
        // Assign role logic here
    }

    public function removeRole($userId, $role) {
        // Remove role logic here
    }
}