2.0.0a2
Pre-release
Pre-release
Information Report
PHP_CodeSniffer now comes with an information report that is able to show you information about how your code is written rather than checking that it conforms to a standard. You can read more about this report, and see example output, on the wiki.
Performance Improvements
A number of minor performance improvements have gone into this version, which will probably only be obvious when checking very large code bases. As a result, there are a few important changes to know about:
- Line length warnings will now be shown for lines that refer to licence and VCS information. The line length sniff previously ignored these lines, which meant that it had to run a regular expression on every line it checked.
- The
$tokens
array has a new length index that you can use to determine the length of the token's content rather than having to callstrlen()
yourself and deal with character encoding. - The use of
in_array()
when checking thePHP_CodeSniffer_Tokens
static vars impacted performance significantly, so they have been restructured so that you can also useisset()
on them. - Custom reports can now specify a
$recordErrors
member var that, when set toFALSE
, will tell PHP_CodeSniffer that it doesn't need to record errors during the run. This gives a significant memory saving if you are using a custom report to output summary information rather than a full list of errors found.
Phar Distribution
For the first time, PHP_CodeSniffer's phpcs
and phpcbf
commands are now available as Phar files. The Phars are still in testing and are known to not work with HHVM, but are an easy way to try out the new 2.0 alpha versions.
curl -OL https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.0.0a2/phpcs.phar
php phphcs.phar /path/to/code
curl -OL https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.0.0a2/phpcbf.phar
php phpcbf.phar /path/to/code
Other Changes
- Added report type --report=info to show information about the checked code to make building a standard easier
- Checks a number of things, such as what line length you use, and spacing are brackets, but not everything
- Still highly experimental
- Generic LineLengthSniff now shows warnings for long lines referring to licence and VCS information
- It previously ignored these lines, but at the expense of performance
- Generic DisallowTabIndent and DisallowSpaceIndent sniffs no longer error when detecting mixed indent types
- Only the first type of indent found on a line (space or indent) is considered
- Lots of little performance improvements that can add up to a substantial saving over large code bases
- Added a "length" array index to tokens so you don't need to call strlen() of them, or deal with encoding
- Can now use isset() to find tokens inside the PHP_CodeSniffer_Tokens static vars instead of in_array()
- Custom reports can now specify a $recordErrors member var; this previously only worked for built-in reports
- When set to FALSE, error messages will not be recorded and only totals will be returned
- This can save significant memory while processing a large code base
- Removed dependence on PHP_Timer
- PHP tokenizer now supports DEFAULT statements opened with a T_SEMICOLON
- The Squiz and PHPCS standards have increased the max padding for statement alignment from 8 to 12
- Squiz EchoedStringsSniff now supports statments without a semicolon, such as PHP embedded in HTML
- Squiz DoubleQuoteUsageSniff now properly replaces escaped double quotes when fixing a doubled quoted string
- Improved detection of nested IF statements that use the alternate IF/ENDIF syntax
- PSR1 CamelCapsMethodNameSniff now ignores magic methods
- Thanks to Eser Ozvataf for the patch
- PSR1 SideEffectsSniff now ignores methods named define()
- PSR1 and PEAR ClassDeclarationSniffs now support traits (request #20208)
- PSR2 ControlStructureSpacingSniff now allows newlines before/after parentheses
- Thanks to Maurus Cuelenaere for the patch
- PSR2 ControlStructureSpacingSniff now checks TRY and CATCH statements
- Squiz SuperfluousWhitespaceSniff now detects whitespace at the end of block comment lines
- Thanks to Klaus Purer for the patch
- Squiz LowercasePHPFunctionsSniff no longer reports errors for namespaced functions
- Thanks to Max Galbusera for the patch
- Squiz SwitchDeclarationSniff now allows exit() as a breaking statement for case/default
- Squiz ValidVariableNameSniff and Zend ValidVariableNameSniff now ignore additional PHP reserved vars
- Thanks to Mikuláš Dítě and Adrian Crepaz for the patch
- Sniff code Squiz.WhiteSpace.MemberVarSpacing.After changed to Squiz.WhiteSpace.MemberVarSpacing.Incorrect (request #20241)
- Fixed bug #20200 : Invalid JSON produced with specific error message
- Fixed bug #20204 : Ruleset exclude checks are case sensitive
- Fixed bug #20213 : Invalid error, Inline IF must be declared on single line
- Fixed bug #20225 : array_merge() that takes more than one line generates error
- Fixed bug #20230 : Squiz ControlStructureSpacing sniff assumes specific condition formatting
- Fixed bug #20234 : phpcbf patch command absolute paths
- Fixed bug #20240 : Squiz block comment sniff fails when newline present
- Fixed bug #20247 : The Squiz.WhiteSpace.ControlStructureSpacing sniff and do-while
- Thanks to Alexander Obuhovich for the patch
- Fixed bug #20248 : The Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff sniff and empty scope
- Fixed bug #20252 : Unitialized string offset when package name starts with underscore