Re: Coding Standard for https://github.com/php/web-php

From: Date: Mon, 27 Jun 2022 13:53:10 +0000
Subject: Re: Coding Standard for https://github.com/php/web-php
References: 1 2  Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-30108@lists.php.net to get a copy of this message
>> As pull requests suggesting coding standard changes have been opened in the past (see >> https://github.com/php/web-php/pull/196 >> <https://github.com/php/web-php/pull/196>) and more recently >> (see https://github.com/php/web-php/pulls/MathiasReker >> <https://github.com/php/web-php/pulls/MathiasReker>) there >> appears to be some controversy around coding standards. >> >> As Christoph Becker suggested, it would be best to reach out in the mailing list (see >> https://github.com/php/web-php/pull/540#issuecomment-1158931457 >> <https://github.com/php/web-php/pull/540#issuecomment-1158931457>). >> >> Personally, I am not interested in discussions around coding standards. It is a boring >> topic, and as long as a coding standard can be enforced with a tool, the best documentation of a >> coding standard is the configuration of the tool that enforces the coding standard. >> >> How do members of the mailing list feel about enforcing a coding standard for >> https://github.com/php/web-php >> <https://github.com/php/web-php> with a tool? > > Ugh, sorry, I've totally missed this mail since there have been a lot of > mails on that particular day. Others might have missed the mail for the > same reasons. > > Anyhow, I'm very much in favor of establishing a coding standard for > web-php (and the other web-* repos). Actually, that should have been > done long ago. > > I'm also in favor of using some tool to enforce that CS, although that > might raise the "we don't want to use third-party tools to avoid > endorsing any particular tools" argument. I hope we can make an > exception in this case, since writing our own CS checker doesn't appear > to be reasonable. > > What do others think about introducing PHP_CodeSniffer[1] or > PHP-CS-Fixer[2] with a suitable coding standard, which could be the PER > Coding Style[3]. > > [1] <https://github.com/squizlabs/PHP_CodeSniffer> Anyone who has used or contributed to squizlabs/php_codesniffer would be aware that it has two tools - phpcs for detecting code violatins - phpcbf for fixing code violations Depending on the employed rules, the capabilities of the tools diverge - the former may detect issues that the latter can not automatically fix. The documentation could be a lot better, too. Given that life is too short to manually fix coding standard issues, I would not suggest to use squizlabs/php_codesniffer. > [2] <https://github.com/FriendsOfPHP/PHP-CS-Fixer> Anyone who has used and contributed to friendsofphp/php-cs-fixer would be aware that it has a single tool - php-cs-fixer for detecting coding standard violations in dry run mode and fixing coding standard violations in non-dry-run mode It has a ton of rules that can easily be configured and is nicely documented. Disclaimer: I have used and contributed to both squizlabs/php_codesniffer and friendsofphp/php-cs-fixer. > [3] <https://www.php-fig.org/per/coding-style/> When it comes to coding standards, there are probably two options: - use a pre-configured coding standard from one of the tools - enable fixers one by one The former has the advantage that you do not have to bother coming up with a coding standard. You shift the responsibility of deciding what belongs in the coding standard to someone else. At the same time, the former has the disadvantage that you do not have control over the coding standard unless you actively contribute to the tools upstream. The latter has the advantage that you can fully control your coding standard in whatever way you like in smaller steps. For example, you could enable one fixer after another, and more easily review code changes. As far as I can tell, the pull requests with the code changes proposed by Matthias Reker in all likelihood are the result of running friendsofphp/php-cs-fixer with a single rule at a time. I currently maintain a configuration template for friendsofphp/php-cs-fixer (see https://github.com/ergebnis/php-cs-fixer-config-template <https://github.com/ergebnis/php-cs-fixer-config-template>). At the end of the day you are probably interested in a list of all available fixers (see https://github.com/ergebnis/php-cs-fixer-config-template/blob/28f1b3337eb4691ab2abc2bddbcce2b349df4ce1/src/RuleSet/Custom.php#L20-L266 <https://github.com/ergebnis/php-cs-fixer-config-template/blob/28f1b3337eb4691ab2abc2bddbcce2b349df4ce1/src/RuleSet/Custom.php#L20-L266>). The fixers are also very nicely documented. Navigate to https://github.com/FriendsOfPHP/PHP-CS-Fixer <https://github.com/FriendsOfPHP/PHP-CS-Fixer>, press T, type in the name of a fixer, end up with the documentation for the fixer. Best regards, Andreas

Attachment: [application/pgp-signature] Message signed with OpenPGP signature.asc
« previous php.webmaster (#30108) next »