What are the best practices for designing classes in PHP to ensure efficient and maintainable code?

When designing classes in PHP for efficient and maintainable code, it is important to follow the principles of object-oriented programming such as encapsulation, inheritance, and polymorphism. Additionally, use proper naming conventions, separate concerns into different classes, and avoid tight coupling between classes.

class User {
    private $id;
    private $username;
    
    public function __construct($id, $username) {
        $this->id = $id;
        $this->username = $username;
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function getUsername() {
        return $this->username;
    }
}

class UserManager {
    public function getUserInfo(User $user) {
        return "User ID: " . $user->getId() . ", Username: " . $user->getUsername();
    }
}