PhpStorm Live Template & Postfix Snippets

All "Builders" Snippets

build

Generate the build method for builders.

build
<template name="build" value="public function build(): $TYPE$&#10;{&#10;    return new $TYPE$($PARAMETERS$$END$);&#10;}" description="Build method" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="" defaultValue="regularExpression(phpClassName(), &quot;Builder&quot;, &quot;&quot;)" alwaysStopAt="false" />
<variable name="PARAMETERS" expression="complete()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="PHP Class Member" value="true" />
</context>
</template>

Live template

fbuild

Generate the encapsulating function for builders.

fbuild
<template name="fbuild" value="function a$FUNCTIONAME$(): $TYPE$ {&#10;&#9;return new $TYPE$();&#10;}" description="function encapsulating a builder" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="FUNCTIONAME" expression="regularExpression(TYPE, &quot;Builder&quot;, &quot;&quot;)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="PHP Statement" value="true" />
</context>
</template>

Live template

with

Generate a "wither" method for builders.

with
<template name="with" value="public function with$NAME$($PARAMETER_TYPE$ $$$PARAMETER_NAME$): self&#10;{&#10;&#9;$clone = clone $this;&#10;&#9;&#10;&#9;$clone-&gt;$PARAMETER_NAME$$END$ = $$$PARAMETER_NAME$;&#10;&#9;&#10;&#9;return $clone;&#10;}" description="Create a wither" toReformat="false" toShortenFQNames="true">
<variable name="PARAMETER_TYPE" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="PARAMETER_NAME" expression="complete()" defaultValue="" alwaysStopAt="true" />
<variable name="NAME" expression="" defaultValue="capitalize(PARAMETER_NAME)" alwaysStopAt="false" />
<context>
<option name="PHP Class Member" value="true" />
</context>
</template>

Live template