vscode-php-getters-setters icon indicating copy to clipboard operation
vscode-php-getters-setters copied to clipboard

Generate CamelCased Methods

Open amaurigabriel opened this issue 7 years ago • 3 comments

This is such a nice extension!

I think it should generate camelCased methods, or at least have an option to enable this feature. Example:

protected $user_name;

should generate methods public function setUserName($name) public function getUserName()

amaurigabriel avatar Feb 16 '18 22:02 amaurigabriel

Thanks for the feedback. Definitely a great addition for those cases where you cannot use camel cased var names.

phproberto avatar Feb 19 '18 08:02 phproberto

Workaround using templates.

https://github.com/phproberto/vscode-php-getters-setters#custom-templates

setter.js

module.exports = (property) => `
	/**
	 * ${property.setterDescription()}
	 *
	 * @param   ${property.getType() ? property.getType() : 'mixed'}  \$${property.getName()}  ${property.getDescription() ? property.getDescription() : ''}
	 *
	 * @return  self
	 */
	public function ${property.setterName().replace(/_([A-Za-z])/g, function (g) { return g[1].toUpperCase(); })}(${property.getTypeHint() ? property.getTypeHint() + ' ' : '' }\$${property.getName()})
	{
		$this->${property.getName()} = \$${property.getName()};

		return $this;
	}
`

getter.js

module.exports = (property) => `
	/**
	 * ${property.getterDescription()}
	 *
	 * @return ${property.getType() ? property.getType() : 'mixed'}
	 */
	public function ${property.getterName().replace(/_([A-Za-z])/g, function (g) { return g[1].toUpperCase(); })}()
	{
		return $this->${property.getName()};
	}
`

dv336699 avatar Jun 12 '19 16:06 dv336699

@diego-vieira thanks, i'am looking for that..

barokurniawan avatar Jan 04 '20 11:01 barokurniawan