This VS Code extension is designed to accelerate the workflow of PHP developers. It automatically generates getter and setter methods and constructors for the private and protected properties of classes in the currently open PHP file. Unlike other similar extensions, this extension supports files containing multiple classes and allows you to select properties separately for each class.
Features
One-Click Generation: Generate getter and setter methods for your PHP class properties with a single click.
Multi-Class Support: If there are multiple classes in the file, you can generate getter and setter methods separately for each.
Customizable Selection: Provides a user-friendly interface where you can select the private properties of each class separately.
Method Insertion Order Selection: Getter and setter methods can be inserted into the class in various orders: getters first, setters first, or alternating.
Constructor Generation: Automatically generates constructors with type hinting and property assignment.
Flexible Sorting: Generated getter/setter methods can be sorted alphabetically (A-Z or Z-A) or according to the order in which the properties are defined.
Fluent Interface: Fluent interface support for setter methods for method chaining.
Modern PHP Support: Support for PHP 7+ type declarations.
Fast and Efficient: Saves you time by speeding up your development process.
Usage
Open your PHP file.
Right-click or open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
Select "Generate Getters and Setters".
Getters and setters will be generated automatically.
Settings
This extension provides the following settings:
phpgsg.getterSetterGenerator.autoGenerate: Skips the quick selection window and automatically generates all available getter/setter methods.
phpgsg.getterSetterGenerator.fluentInterface: Adds return $this; for fluent interface (method chaining) in setter methods.
phpgsg.getterSetterGenerator.indentSize: Specifies the size of an indent (as a number of spaces).
phpgsg.getterSetterGenerator.indentWithTab: Uses tab character as the indent character instead of spaces. (indentSize option is calculated as 1)
phpgsg.getterSetterGenerator.sortMethods: You can prioritize getters or setters, or sort them mixed when arranging methods.
phpgsg.getterSetterGenerator.orderBy: You can choose alphabetical sorting or the property order defined in the class when sorting methods.
phpgsg.getterSetterGenerator.contextMenu.constructor: Shows or hides the "Generate Constructor" option in the context menu.
phpgsg.getterSetterGenerator.contextMenu.getter: Shows or hides the "Generate Getters" option in the context menu.
phpgsg.getterSetterGenerator.contextMenu.setter: Shows or hides the "Generate Setters" option in the context menu.
phpgsg.getterSetterGenerator.contextMenu.getterAndSetter: Shows or hides the "Generate Getters and Setters" option in the context menu.