Add a Phpactor template for creating collections

This commit is contained in:
Oliver Davies 2025-01-08 22:00:00 +00:00
parent d56eef8070
commit fd0eb9166c
2 changed files with 23 additions and 0 deletions
phpactor/templates/collection

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace {{ prototype.namespace }};
{% for class in prototype.classes %}
final class {{ class.name }} implements \IteratorAggregate {
public function __construct(private array $items = []) {
}
public function getIterator(): \Iterator {
return new \ArrayIterator($this->items);
}
public function toArray(): array {
return $this->items;
}
}
{% endfor %}