Open maks-rafalko opened 6 years ago
@borNfreee thanks for your proposal. At first sight I'd say we shouldn't make this configurable ... because the current behaviour is configurable (more precisely, it's flexible).
If you generate fluent setters, you can decide if you prefer to use them fluently or not. Both ways work. But if you don't make them fluent or make it configurable ... user must check which is the format to use, etc.
But if you don't make them fluent or make it configurable ... user must check which is the format to use, etc.
Could you please explain what do you mean here?
Some background of why I think there should be an option:
We are using api-platform
and Sonata Admin
, and to take everything from this 2 libraries, unfortunately, we have to use getters/setters.
When we generate entities, we have to go through each method and replace return type, and remove return $this
line
Developer can miss one of the methods, ending up with 2 types of setters - one is fluent, another is not (just a human mistake, that's easy)
When you use a fluent setter (alone, not as a chain), for example, $user->setName('John');
, my IDE with PhpInspection EA Extended plugin complains that the returned value is not used and is being ignored, underlining it with a red line which is quite annoying.
If this should be implemented, then we maybe should support it to be configurable with the bundle's configuration.
Yea, I'd be fine with this - as configuration in the bundle itself (not as an interactive question)... which I think would work better for your use-case anyways (one consistent way of generating entities through a project, every time).
Someone just needs to add the config and make the generate respect it - it's a "fairly" easy change :).
Cheers!
If someone tries to implement this: remember that some generated code rely on these fluid interfaces.
Hi everyone!
The only one mention about fluent setters I found is here: https://github.com/symfony/maker-bundle/pull/104, but nothing has been implemented as far as I see from the source code.
There is a flag that checks whether to generate fluent setters or not, here
https://github.com/symfony/maker-bundle/blob/705d3a2194d2d151299d4c3d61dc03dea7494357/src/Util/ClassSourceManipulator.php#L947-L951
but it's impossible to override the default value (which is
true
- setters are fluent), because manipulator class is instantiated always withtrue
:https://github.com/symfony/maker-bundle/blob/705d3a2194d2d151299d4c3d61dc03dea7494357/src/Maker/MakeEntity.php#L769
Note the last parameter
https://github.com/symfony/maker-bundle/blob/705d3a2194d2d151299d4c3d61dc03dea7494357/src/Util/ClassSourceManipulator.php#L57
Proposal
What do you think about adding an option that will allow overriding this flag? For example:
or something like that.
If this would be useful from your point of view, I would be able to send a PR.