Add a Phpactor template for creating collections
This commit is contained in:
parent
d56eef8070
commit
fd0eb9166c
|
@ -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
|
||||
|
|
22
phpactor/templates/collection/SourceCode.php.twig
Normal file
22
phpactor/templates/collection/SourceCode.php.twig
Normal 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 %}
|
Loading…
Reference in a new issue