User:Sumit.iitp/static analysis tools

Static Analysis tools for mediawiki
This is a GSoC project proposal to create tools for checking the integrity of code submitted to mediawiki repositories against its set of code conventions.

Phabricator report:

Profile Information:

 * Name: Sumit Asthana
 * Email: asthana.sumit23@gmail.com
 * IRC nick: codezee
 * Location: India
 * Typical working hours: 6PM to 2AM before 26th April, 2PM to 12AM after 26th April(Indian Standard Time)

Synopsis
Presently, the mediawiki code is checked jenkins tests for potential errors, as well as violations of spaces. However it does not check if the code conventions of mediawiki are being properly followed. E.g if a user gives a space before a php open tag, its not an error in itself, and hence not flagged as one, but its a potential code style error. Thus, phpcs [code sniffer] has been introduced to check for errors. The project mainly consists of developing phpcs sniffs with respect to mediawiki code conventions

Workflow
The following sniffs have been proposed to be introduced:
 * 1) Usage of $dbr->query directly instead of the $dbr->select wrapper
 * 2) Using wfMessage when $this->msg is usable
 * 3) Using globals ($wgUser, $wgRequest) when their context equivalents could be used instead ($this->getUser, $this->getRequest)
 * 4) Modifying certain globals ($wgUser, $wgResourceModules, etc) inside a $wgExtensionFunction where it is either too early or late to do so
 * 5) Sniff to check indent of multiline statements,except switch cases
 * 6) Space after if,while,foreach,for,switch
 * 7) Disallow multiline ternary operator
 * 8) Disallow 'endif syntax for if conditional
 * 9) Sniff to give preference to use of ! over empty
 * 10) Enforce use of '===' over '=='
 * 11) Sniff to detect documentation of parameters for functions using parameters
 * 12) Sniff to suppress use of $_GET, $_POST, over $request->get(...)
 * 13) Sniff to disallow the use of @ in PHP for suppressing errors
 * 14) Sniff to detect inadequate spacing
 * 15) Sniff to enforce use of MWException over generic Exception

Existing sniffs that can be ported from Squizlabs

 * 1) [GenericSniffs Whitespace DisallowSpaceIndentSniff]
 * 2) Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
 * 3) DocCommentSniff for vlidating doc comments
 * 4) GenericSniffs EndFileNewLineSniff
 * 5) GenericSniffs LowerCaseFileNameSniff
 * 6) GenericSniffs DisallowMultipleStatementsSniff
 * 7) Generic Sniffs NoSpaceAfterCastSniff