tbn / getter-trait-bundle
Installs: 3 282
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.2
- phpdocumentor/reflection-docblock: ^5.4.1
- phpdocumentor/type-resolver: ^1.4
- symfony/framework-bundle: ^7.1
- symfony/property-info: ^7.1
- symfony/string: ^7.1
Requires (Dev)
- doctrine/collections: ^2.1
- nyholm/symfony-bundle-test: ^3.0
- phpunit/phpunit: ^10.3
- symfony/uid: ^7.1
This package is auto-updated.
Last update: 2024-11-03 19:37:09 UTC
README
Symfony Bundle that generates getters and setters inside a trait.
Why ? Basics getters brings no information about the class.
The classes are quickly long for no "business" reason.
Having only the redefined method allows to spot the method with business purpose.
Installation
composer require --dev "tbn/getter-trait-bundle"
In config/bundles.php
, add the bundle to the dev environment
return [ ... tbn\GetterTraitBundle\GetterTraitBundle::class => ['dev' => true,], ];
Usage
Add the GetSetTrait
attribute to your class
use tbn\GetterTraitBundle\Attributes\GetSetTrait; // add this line #[GetSetTrait] // add this line class MyClass { private String $name; }
Run the ./bin/console generate:getter:traits
command
A new file is automatically generated in the same folder and contains the getters and setters for the MyClass
class.
When a property is modified or added, you have to re-run the command in order to update the traits.
Use the generated trait.
#[GetSetTrait] class MyClass { use MyClassTrait; // add this line private String $name; }
I need to redefine the method
Just copy/paste the generated code inside your class and update it to your needs.