Last Updated: February 25, 2016
· bendihossan

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};
    $this->${FIELD_NAME} = $${PARAM_NAME};
    return $this;