What are the recommended ways to improve the structure and readability of PHP code, especially when integrating older code snippets into a new project?

When integrating older PHP code snippets into a new project, it is important to improve the structure and readability of the code for better maintainability. One way to do this is by following coding standards such as PSR-1 and PSR-2, which define guidelines for naming conventions, indentation, and other coding practices. Additionally, refactoring the code to use modern PHP features and design patterns can also help improve its readability and maintainability.

// Example of refactored code snippet using PSR-1 and PSR-2 coding standards
<?php

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;
    }
}

$user = new User(1, 'john_doe');
echo $user->getId();
echo $user->getUsername();