Skip to content

Instantly share code, notes, and snippets.

@pierswarmers
Created March 3, 2019 22:07
Show Gist options
  • Select an option

  • Save pierswarmers/08de0db3d0fd0815772e6a38bf47e208 to your computer and use it in GitHub Desktop.

Select an option

Save pierswarmers/08de0db3d0fd0815772e6a38bf47e208 to your computer and use it in GitHub Desktop.
<template name="coll" value="class $COLLECTION$ implements \Countable, \IteratorAggregate&#10;{&#10; private $$$INTERNAL_STORE$;&#10;&#10; public function __construct($ENCAPSULATED_TYPE$ ... $$$INTERNAL_STORE$) &#10; { &#10; $this-&gt;$INTERNAL_STORE$ = $$$INTERNAL_STORE$; &#10; }&#10;&#10; public function count(): int &#10; { &#10; return count($this-&gt;$INTERNAL_STORE$); &#10; }&#10; &#10; /**&#10; * @return \Traversable|$ENCAPSULATED_TYPE$[]&#10; */&#10; public function getIterator(): \Traversable &#10; {&#10; foreach ($this-&gt;$INTERNAL_STORE$ as $$$ITEM_VAR$)&#10; {&#10; yield $$$ITEM_VAR$;&#10; }&#10; }&#10; }" description="Typed immutable collection" toReformat="true" toShortenFQNames="true">
<variable name="COLLECTION" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="INTERNAL_STORE" expression="camelCase(COLLECTION)" defaultValue="" alwaysStopAt="false" />
<variable name="ENCAPSULATED_TYPE" expression="capitalize(firstWord(spaceSeparated(COLLECTION)))" defaultValue="" alwaysStopAt="true" />
<variable name="ITEM_VAR" expression="camelCase(ENCAPSULATED_TYPE)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="PHP" value="true" />
</context>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment