We currently have a PHPCS standard that MediaWiki core and a decent number of extensions are using.. We've seen the value of standardizing our code and making sure it is enforced in an automated manner. We are relying less on humans to worry about style and let them focus on the actual code.
That said, we can make phpcs more useful by adding more MediaWiki-specific sniffs. Some quick ideas I had:
- Usage of $dbr->query() directly instead of the $dbr->select() wrapper
- Using wfMessage() when $this->msg() is usable
- Using globals ($wgUser, $wgRequest) when their context equivalents could be used instead ($this->getUser(), $this->getRequest())
- Modifying certain globals ($wgUser, $wgResourceModules, etc) inside a $wgExtensionFunction where it is either too early or late to do so
I'm sure we can easily come up with a longer list based on people's code review checklists. In addition, some of the structure tests (tests/phpunit/structure in core) should become sniffs instead.
Furthermore, we currently really only use the check functionality of phpcs - finding errors. phpcs also supports automatically fixing errors through phpcbf. We should make sure that as many of our error finding sniffs as possible can be automatically fixed (as is reasonable), and that we have proper test coverage for that functionality.
We use PHP CodeSniffer and a custom standard in mediawiki/tools/codesniffer.git. It is versioned and published on packagist as mediawiki/mediawiki-codesniffer.
Addshore has done some initial work in enhancing the standard for MW core compatability (https://gerrit.wikimedia.org/r/153399), which would be a good place to start.
- Mentors : @EBernhardson, @Legoktm, ( @Addshore part time )
- Skills: PHP, basic familiarity with MediaWiki code conventions
- Estimated project time for a senior contributor: 2-3 weeks probably
- Microtasks: T92744, more coming soon