Skip to content

Instantly share code, notes, and snippets.

@Raphhh
Last active January 28, 2016 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raphhh/2fa957972a3eb2b3db18 to your computer and use it in GitHub Desktop.
Save Raphhh/2fa957972a3eb2b3db18 to your computer and use it in GitHub Desktop.
Templates for getter and setter in PHPStorm

#PHP getter method

/**
 * Getter of $${PARAM_NAME}
 *
 * @return ${TYPE_HINT}
 */
#if (${TYPE_HINT} == "bool" || ${TYPE_HINT} == "boolean")
public ${STATIC} function ${PARAM_NAME}()
{
#else
public ${STATIC} function get${NAME}()
{
#end
#if (${STATIC} == "static")
    return self::$${FIELD_NAME};
#else
    return $this->${FIELD_NAME};
#end
}

#PHP setter method

/**
 * Setter of $${PARAM_NAME}
 *
 * @param ${TYPE_HINT} $${PARAM_NAME}
 */
#if(${TYPE_HINT} == "" || ${TYPE_HINT} == "string" || ${TYPE_HINT} == 
"int" || ${TYPE_HINT} == "integer" || ${TYPE_HINT} == "float" || 
${TYPE_HINT} == "bool" || ${TYPE_HINT} == "boolean")
public ${STATIC} function set${NAME}($${PARAM_NAME})
{
#if (${STATIC} == "static")
    self::$${FIELD_NAME} = (${TYPE_HINT}) $${PARAM_NAME};
#else
    $this->${FIELD_NAME} = (${TYPE_HINT}) $${PARAM_NAME};
#end
}
#else
public ${STATIC} function set${NAME}(${TYPE_HINT} $${PARAM_NAME})
{
#if (${STATIC} == "static")
    self::$${FIELD_NAME} = $${PARAM_NAME};
#else
    $this->${FIELD_NAME} = $${PARAM_NAME};
#end
}
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment