Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alle/bd2cd3b13284ff918a286e0236c40bc7 to your computer and use it in GitHub Desktop.
Save alle/bd2cd3b13284ff918a286e0236c40bc7 to your computer and use it in GitHub Desktop.
PHPStorm code template for getters without `get` prefix and first letter decapitalized
#if (${TYPE_HINT} == "mixed")
/**
* @return ${TYPE_HINT}
*/
#end
public ${STATIC} function ${FIELD_NAME}()#if(${RETURN_TYPE}): ${RETURN_TYPE}#end
{
#if (${STATIC} == "static")
return self::$${FIELD_NAME};
#else
return $this->${FIELD_NAME};
#end
}
@balazscsaba2006
Copy link

If you want to also keep the is prefix, this would work:

public ${STATIC} function #if($GET_OR_IS.substring(0,2) == “is”)is${NAME}#{else}$NAME.substring(0,1).toLowerCase()$NAME.substring(1)#end ()#if(${RETURN_TYPE}): ${RETURN_TYPE}#else#end
{
#if (${STATIC} == “static”)
    return self::$${FIELD_NAME};
#else
    return $this->${FIELD_NAME};
#end
}

@alle
Copy link
Author

alle commented Apr 17, 2023

After this long time (a gist from 5 years ago), thank you for the insight!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment