Feature #72174
closed
Fluent setter for AbstractDomainObject->setPid()
Added by Matthias Schröder over 8 years ago.
Updated over 3 years ago.
Sprint Focus:
Needs Decision
Description
public function setPid($pid) {...}
should not return void but $this to use it fluently.
- Status changed from New to Needs Feedback
Why exactly? There is no domain model/object in TYPO3 which spurs a fluent interface, why should this setter be an exception?
If we change this we have to change the DomainObjectInterface too, which is a breaking change.
This one I came across several times when creating a new domain model object.
I think it would be nice, if all setters implemented the fluent interface (if possible), because it is much ore convenient and improves code readability.
Example:
$event = GeneralUtility::makeInstance(Event::class)
$event->setPid(101);
$event
->setTeaserText($faker->text(100))
->setCategory(rand(1, 3))
->setVenue($faker->text(15))
->setAddress($faker->address)
...
;
- Status changed from Needs Feedback to New
- Target version set to Candidate for Major Version
- Sprint Focus set to Needs Decision
- Status changed from New to Rejected
I see your point here, but considering adding this as "breaking" change for a fluent API seems a bit much. Also, personally, I'd recommend using Factories or the constructor to set up the object, as this brings the code that uses the domain model in a defined state. See latest PHP8 additions, which directly point to such features.
Sorry (also for the late reply).
Also available in: Atom
PDF