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

View file

@ -1,4 +1,5 @@
code_transform.class_new.variants: code_transform.class_new.variants:
collection: collection
default: default default: default
drupal-functional-test: drupal-functional-test drupal-functional-test: drupal-functional-test
drupal-kernel-test: drupal-kernel-test drupal-kernel-test: drupal-kernel-test

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