Per Manual:Coding conventions/PHP#String literals, single quotes are preferred when they are equivalent to double ones. Yet, this is not enforced by PHPCS (all tests were green). Is it possible (or desirable) to lint this? I think all meaningful linting is useful, as it makes our code base more consistent.
Topic on Manual talk:Coding conventions
Jump to navigation Jump to search
Reply to "Enforce quote styles in PHP"
Enforce quote styles in PHP
I don't think this should be enforced in code review, PHPCS, or otherwise in CI. We have a general guideline to follow, but I don't see it helping us to require code to change back and forth between two formats on a regular basis just due to the addition or removal of a character. Local consistently and productivity are I think more important factors.
When all else is equal, e.g. writing new code, or most strings in a method or file are equally simple, then our convention says to default to single quotes. Beyond that I don't think it's worth worrying about. In my opinion, string quoting isn't the sort of thing where cognitive overhead is induced by having variants or where it adds friction during review/auditing/debugging. You are goint to encounter both variants no matter what.
In my view, the guideline mainly exists as a tie-breaker when there's uncertaintity so that nobody has to discuss which one to use if they're not sure. But when modifying existing code, or once code has been put up for review, it's imho not worth changing or discussing further.