Last active
September 19, 2024 05:47
-
-
Save mdalaminbey/81e68d998905f189592f817e43cc4a9a to your computer and use it in GitHub Desktop.
VS Code PHP Getter And Setter SnakeCase Template https://github.com/cvergne/vscode-php-getters-setters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Getter | |
| module.exports = (property) => { | |
| // Determine the return type based on the property type | |
| const returnType = property.isNullable() ? `?${property.getType()}` : property.getType(); | |
| return ` | |
| /** | |
| * ${property.getterDescription()} | |
| * | |
| * @return ${returnType || 'mixed'} | |
| */ | |
| public function ${toSnakeCase(property.getterName())}(): ${returnType || 'mixed'} { | |
| return $this->${property.getName()}; | |
| } | |
| `; | |
| }; | |
| function toSnakeCase(str) { | |
| return str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`); | |
| } | |
| //Setter | |
| module.exports = (property) => { | |
| // Determine the type hint based on whether the property is nullable | |
| const typeHint = property.isNullable() ? `?${property.getTypeHint()}` : property.getTypeHint(); | |
| return ` | |
| /** | |
| * ${property.setterDescription()} | |
| * | |
| * @param ${typeHint || 'mixed'} \$${property.getName()} ${property.getDescription() || ''} | |
| * | |
| * @return self | |
| */ | |
| public function ${toSnakeCase(property.setterName())}( ${typeHint ? typeHint + ' ' : '' }\$${property.getName()} ): self { | |
| $this->${property.getName()} = \$${property.getName()}; | |
| return $this; | |
| } | |
| `; | |
| }; | |
| function toSnakeCase(str) { | |
| return str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment