Since I can use PHP 8 in my Flow-based projects, I convert doc-comment-based annotations to native PHP annotations where I can. The code feels much tidier afterwards, and I like how PhpStorm highlights the annotations by coloring them yellow.
Now, where I’m still undecided about is, if I should generally optimize the class properties by putting the annotation into the same line like the property declaration.
What’s your preference? Maybe we can even decide on a general rule for future Flow coding guidelines?
I think a general rule would be great, I would go with the first version, might be a bit long for really long class/property names but should read nicely, the problem starts then with eg InjectConfiguration, with path and package that might become quite long in itself and then would need an exception to the rule I guess? So from that perspective variant 2 might just be the more consistent style.
I prefer the first version as it gives a very compact overview of the class-properties. If we define a rule we should also consider cases where multiple and long annotations are needed.
yes i can aggree with @sorenmalling and @bwaidelich - constructor injection is also my favorite for the domain especially since promoted properties make it even cleaner ^^
… and i would stick to the second one - feels calming to have some white space floating around (says my half as a FE ^^)
While I optimized some code recently to have class properties defined like in the first example, those had no injections. As soon as those are thrown in the mix, I’d rather use the second format.
And especially considering other, multiple and/or longer annotations, the need for an exception from the rule is removed. Consistency FTW.