Skip to content

Instantly share code, notes, and snippets.

@ephrin
Last active October 12, 2015 11:30
Show Gist options
  • Save ephrin/25ef81e8933b34d0355b to your computer and use it in GitHub Desktop.
Save ephrin/25ef81e8933b34d0355b to your computer and use it in GitHub Desktop.
PHPStorm: Editor -> File and Code Templates: Code -> PHP Setter Method
/**
* @param ${TYPE_HINT} $${PARAM_NAME}
* @return static
*/
#set($th = $TYPE_HINT)
#set($ln = "|")
#set($be = "[]")
#set($aw = "array")
#set($c = ["int", "integer", "mixed", "str", "string", "bool", "boolean", "float", "double"])
#set($o = '')
#if ($c.contains($th))
#set($hint = "")
#elseif($th.contains($be) && !$th.contains($ln))
#set($hint = "array ")
#elseif($th.contains($be) && $th.contains($ln) && $th.contains($aw))
#set($hint = "array ")
#elseif($th.contains($be) && $th.contains($ln) && !$th.contains($aw))
#set($hint = "")
#elseif(!$th.contains($be) && $th.contains($ln) && !$th.contains($aw))
#set($hint = "")
#else
#set($hint = "$TYPE_HINT ")
#end
public ${STATIC} function set${NAME}(${hint}$${PARAM_NAME})
{
#if (${STATIC} == "static")
self::$${FIELD_NAME} = $${PARAM_NAME};
#else
$this->${FIELD_NAME} = $${PARAM_NAME};
#end
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment