Make PhpStorm generated setter return $this
PhpStorm features a lot of standard IDE features like generating getter/setter methods. But I like my setters to return the object they're modifying (ie: return $this;).
Open PhpStorm's Preferences and "File and Code Templates" menu, under the "Code" tab there's an option called "PHP Setter Method". Modify it to look like this:
/**
* @param ${TYPE_HINT} $${PARAM_NAME}
* @return ${CLASS_NAME}
*/
public ${STATIC} function set${NAME}($${PARAM_NAME})
{
#if (${STATIC} == "static")
self::$${FIELD_NAME} = $${PARAM_NAME};
#else
$this->${FIELD_NAME} = $${PARAM_NAME};
#end
return $this;
}
Written by Steffan Harries
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#