How can the EVA principle be applied in PHP programming to improve code structure?

Issue: The EVA principle (Encapsulate, Validate, and Assert) can be applied in PHP programming to improve code structure by encapsulating related functionality into classes or functions, validating input data to ensure it meets the expected criteria, and asserting conditions to handle errors or edge cases effectively. PHP Code Snippet:

class User {
    private $name;

    public function setName($name) {
        if (!is_string($name)) {
            throw new InvalidArgumentException('Name must be a string');
        }
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

$user = new User();
$user->setName('John Doe');
echo $user->getName(); // Output: John Doe