plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

[PSR-12] Method visibility

Open loilo opened this issue 6 years ago • 6 comments
trafficstars

Disclaimer: I am aware that it's not make-or-break for Prettier to adhere to PSR-12.

However, now that it is officially accepted as a standard, we should discuss (and, if necessary, reject) each current violation of PSR-12 — if only to have point to refer to in future discussions or issues.

PSR-12 Violations

  1. Visibility MUST be declared on all methods. – Section 4.4

    Solving this reliably would need an --engine flag if we attempt to support PHP 4 (and, therefore, the var keyword).

Playground Link (contains all listed violations)

loilo avatar Sep 17 '19 00:09 loilo

That said, I'm not sure whether auto-adding visibility keywords is in scope for a formatter at all, so feel free to close this without further discussion.

loilo avatar Sep 17 '19 00:09 loilo

Hm, without visibility it is always public?

alexander-akait avatar Sep 23 '19 10:09 alexander-akait

Yes.

loilo avatar Sep 23 '19 11:09 loilo

/cc @czosel what do you think, with --engine option it is safe.

Anyway i aware that, for many it can be very annoying.

alexander-akait avatar Sep 23 '19 11:09 alexander-akait

Hmm, I'm a bit torn about this one (and probably some other aspects of PSR-12 as well). On the one hand one can apply the same reasoning than for PSR-2, on the other hand this seems a bit verbose. I think it would be very helpful to get a sense of where the PHP community stands on these points. Are the popular projects advocating for PSR-12, or even implementing it already? Are there projects which deliberately decided against implementing PSR-12 or some parts of it?

czosel avatar Sep 23 '19 15:09 czosel

Same comments as here and here (seems out of scope).

glen-84 avatar Dec 18 '19 10:12 glen-84