diff --git a/phpactor/phpactor.yml b/phpactor/phpactor.yml index 536f4083..1c755d12 100644 --- a/phpactor/phpactor.yml +++ b/phpactor/phpactor.yml @@ -1,4 +1,5 @@ code_transform.class_new.variants: + collection: collection default: default drupal-functional-test: drupal-functional-test drupal-kernel-test: drupal-kernel-test diff --git a/phpactor/templates/collection/SourceCode.php.twig b/phpactor/templates/collection/SourceCode.php.twig new file mode 100644 index 00000000..15a9731f --- /dev/null +++ b/phpactor/templates/collection/SourceCode.php.twig @@ -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 %}