Laminas Code: create arbitrary PHP classes with this simple generator

Code
<?php

use Laminas\Code\Generator\ClassGenerator;
use 
Laminas\Code\Generator\MethodGenerator;
use 
Laminas\Code\Generator\PropertyGenerator;

$classGenerator = new ClassGenerator(
    
'Foo',
    
'My\Namespace'
);

$classGenerator->setImplementedInterfaces(
    [
'IteratorAggregate']
);
$classGenerator->addProperties([
    new 
PropertyGenerator('bar'1),
    
'baz',
]);
$classGenerator->addUse('IteratorAggregate');
$classGenerator->addUse('ArrayIterator');

$constructMethod = new MethodGenerator('__construct', ['baz']);
$constructMethod->setBody('$this->baz = $baz;');

$getIteratorMethod = new MethodGenerator('getIterator');
$getIteratorMethod->setBody(
    
'return new ArrayIterator([$this->baz, $this->bar]]);'
);

$classGenerator->addMethods([
    
$constructMethod,
    
$getIteratorMethod,
]);

echo 
'<pre>'.$classGenerator->generate().'</pre>';
Result
namespace My\Namespace;

use IteratorAggregate;
use ArrayIterator;

class Foo implements IteratorAggregate
{

    public $bar = 1;

    public $baz = null;

    public function __construct($baz)
    {
        $this->baz = $baz;
    }

    public function getIterator()
    {
        return new ArrayIterator([$this->baz, $this->bar]]);
    }


}
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8