Important changes
The repository has moved
As of July 13 2018, the PHPCompatibility repository has moved from the personal account of Wim Godden wimg
to its own organization PHPCompatibility
.
Composer users are advised to update their composer.json
. The dependency is now called phpcompatibility/php-compatibility
.
Framework/CMS specific PHPCompatibility rulesets
Within this new organization, hosting will be offered for framework/CMS specific PHPCompatibility rulesets.
The first two such repositories have been created and are now available for use:
If you want to make sure you have all PHPCompatibility rulesets available at any time, you can use the PHPCompatibilityAll package GitHub | Packagist.
For more information, see the Readme and Contributing guidelines.
Changes expected in PHPCompatibility 9.0.0
The next version of PHPCompatibility will include a major directory layout restructuring which means that the sniff codes of all sniffs will change.
In this same release, support for PHP_CodeSniffer 1.5.x will be dropped. The new minimum supported PHPCS version will be 2.3.0.
For more information about these upcoming changes, please read the announcement.
The 9.0.0
release is expected to be ready later this summer.
See all related issues and PRs in the 8.2.0 milestone.
Added
- 🌟 New
ArgumentFunctionsUsage
sniff to detect usage of thefunc_get_args()
,func_get_arg()
andfunc_num_args()
functions and the changes regarding these functions introduced in PHP 5.3. #596. Fixes #372. - 🌟 New
DiscouragedSwitchContinue
sniff to detectcontinue
targetting aswitch
control structure for whichE_WARNINGS
will be thrown as of PHP 7.3. #687 - 🌟 New
NewClassMemberAccess
sniff to detect class member access on instantiation as added in PHP 5.4 and class member access on cloning as added in PHP 7.0. #619. Fixes #53. - 🌟 New
NewConstantScalarExpressions
sniff to detect PHP 5.6 scalar expression in contexts where PHP previously only allowed static values. #617. Fixes #399. - 🌟 New
NewGeneratorReturn
sniff to detectreturn
statements within generators as introduced in PHP 7.0. #618 - 🌟 New
PCRENewModifiers
sniff to initially detect the newJ
regex modifier as introduced in PHP 7.2. #600. Fixes #556. - 🌟 New
ReservedFunctionNames
sniff to report on double underscore prefixed functions and methods. This was previously reported via an upstream sniff. #581 - 🌟 New
NewTrailingComma
sniff to detect trailing comma's in function calls, method calls,isset()
andunset()
as will be introduced in PHP 7.3. #632 - 🌟 New
Upgrade/LowPHPCS
sniff to give users of old PHP_CodeSniffer versions advance warning when support will be dropped in the near future. #693 - ⭐
NewClasses
sniff: check for some 40+ additional PHP native classes added in various PHP versions. #573 - ⭐
NewClosure
sniff: check for usage ofself
/parent
/static::
being used within closures, support for which was only added in PHP 5.4. #669. Fixes #668. - ⭐
NewConstants
sniff: recognize constants added by the PHP 5.5+ password extension. #626 - ⭐
NewFunctionParameters
sniff: recognize a number of additional function parameters added in PHP 7.0, 7.1 and 7.2. #602 - ⭐
NewFunctions
sniff: recognize the PHP 5.1 SPL extension functions, the PHP 5.1.1hash_hmac()
function, the PHP 5.6pg_lo_truncate()
function, more PHP 7.2 Sodium functions and the new PHP 7.3is_countable()
function. #606, #625, #640, #651 - ⭐
NewHashAlgorithms
sniff: recognize the new hash algorithms which were added in PHP 7.1. #599 - ⭐
NewInterfaces
sniff: check for the PHP 5.0Reflector
interface. #572 - ⭐
OptionalRequiredFunctionParameters
sniff: detect missing$salt
parameter in calls to thecrypt()
function (PHP 5.6+). #605 - ⭐
RequiredOptionalFunctionParameters
sniff: recognize that the$varname
parameter ofgetenv()
and the$scale
parameter ofbcscale()
have become optional as of PHP 7.1 and 7.3 respectively. #598, #612 - ⭐ New
AbstractFunctionCallParameterSniff
to be used as a basis for sniffs examining function call parameters. #636 - ⭐ New
getReturnTypeHintName()
utility method to thePHPCompatibility\Sniff
class. #578, #642 - ⭐ New
isNumber()
,isPositiveNumber()
andisNegativeNumber()
utility methods to thePHPCompatibility\Sniff
class. #610, #650 - ⭐ New
isShortList()
utility method to thePHPCompatibility\Sniff
class. #635 - ⭐ New
getCommandLineData()
method to thePHPCompatibility\PHPCSHelper
class to provide PHPCS cross-version compatible access to command line info at run time. #693 - ⭐ Duplicate of upstream
findEndOfStatement()
method to thePHPCompatibility\PHPCSHelper
class to allow for PHPCS cross-version usage of that method. #614 - ☔ additional unit test to confirm that the
PHPCompatibility\Sniff::isUseOfGlobalConstant()
method handles multi-constant declarations correctly. #587 - ☔ additional unit tests to confirm that the
PHPCompatibility\Sniff::isClassProperty()
method handles multi-property declarations correctly. #583 - 📚 Readme & Contributing: add information about the framework/CMS specific rulesets. Related PRs: #615, #624, #648, #674, #685, #694. Related to issue #530.
- 📚 Readme: information about the PHPCS 3.3.0 change which allows for a
testVersion
in a custom ruleset to be overruled by the command-line. #607
Changed
- 📚 Adjusted references to the old repository location throughout the codebase to reflect the move to a GitHub organization. #689
This repository will now live in https://github.com/PHPCompatibility/PHPCompatibility and the Packagist reference will now bephpcompatibility/php-compatibility
. - ✅ The
getReturnTypeHintToken()
utility method has been made compatible with the changes in the PHPCS tokenizer which were introduced in PHP_CodeSniffer 3.3.0. #642. Fixes #639. - 📌
ConstantArrayUsingConst
: improved handling of multi-constant declarations. #593 - 📌
NewHeredocInitialize
: improved handling of constant declarations using theconst
keyword.
The sniff will now also report on multi-declarations for variables, constants and class properties and on using heredoc as a function parameter default. #641 - 📌
ForbiddenEmptyListAssignment
: this sniff will now also report on empty list assignments when the PHP 7.1 short list syntax is used. #653 - 📌 The
ForbiddenNegativeBitshift
sniff would previously only report on "bitshift right". As of this version, "bitshift left" and bitshift assignments will also be recognized. #614 - 📌 The
NewClasses
andNewInterfaces
sniffs will now also report on new classes/interfaces when used as return type declarations. #578 - 📌 The
NewScalarTypeDeclarations
sniff will now recognizeparent
as a valid type declaration.
The sniff will now also throw an error about usingself
andparent
when PHP < 5.2 needs to be supported as PHP 5.1 and lower would presume these to be class names instead of keywords. #595 - 📌 The
PregReplaceEModifier
sniff - and thePCRENewModifiers
sniff by extension - will now correctly examine and report on modifiers in regexes passed via calls topreg_replace_callback_array()
. #600, #636 - 📌
getReturnTypeHintToken()
utility method: improved support for interface methods and abstract function declarations. #652 - 📌 The
findExtendedClassName()
,findImplementedInterfaceNames()
,getMethodParameters()
utility methods which are duplicates of upstream PHPCS methods, have been moved from thePHPCompatibility\Sniff
class to thePHPCompatibility\PHPCSHelper
class and have become static methods. #613 - ✅
getReturnTypeHintToken()
utility method: align returned$stackPtr
with native PHPCS behaviour by returning the last token of the type declaration. #575 - ✅ PHPCS cross-version compatibility: sync
getMethodParameters()
method with improved upstream version. #643 - ✏️ The
MbstringReplaceEModifier
,PregReplaceEModifier
and thePregReplaceEModifier
sniffs nowextend
the newAbstractFunctionCallParameterSniff
class. This should yield more accurate results when checking whether one of the target PHP functions was called. #636 - ✏️
DeprecatedNewReference
sniff: minor change to the error text and code - wasForbidden
, nowRemoved
-. Custom rulesets which explicitly excluded this error code will need to be updated. #594 - ✏️
NewScalarTypeDeclarations
sniff: minor change to the error message text.#644 - ☔ The unit test framework now allows for sniffs in categories other than
PHP
. #634 - ☔ Boyscouting: fixed up some (non-relevant) parse errors in a unit test case file. #576
- 💚 Travis: build tests are now also being run against the lowest supported PHPCS 3.x version. Previously only the highest supported PHPCS 3.x version was tested against. #633
- 📚 Readme: Improved Composer install instructions. #690
- 📚 Minor documentation fixes. #672
- 🔧 Minor performance optimizations and code simplifications. #592, #630, #671
- 🔧 Composer: Various improvements, including improved information about the suggested packages, suggesting
roave/security-advisories
, allowing for PHPUnit 7.x. #604, #616, #622, #646 - 🔧 Various Travis build script improvements, including tweaks for faster build time, validation of the
composer.json
file, validation of the framework specific rulesets. #570, #571, #579, #621, #631 - 🔧 Build/PHPCS: made some more CS conventions explicit and start using PHPCS 3.x options for the PHPCompatibility native ruleset. #586, #667, #673
- 🔧 Some code style clean up and start using the new inline PHPCS 3.2+ annotations where applicable. #586, #591, #620, #673
Removed
- 🚫 PHPCompatibility no longer explicitly supports PHP_CodeSniffer 2.2.0. #687, #690
- 🚫 The PHPCompatibility ruleset no longer includes the PHPCS native
Generic.NamingConventions.CamelCapsFunctionName
. Double underscore prefixed function names are now being reported on by a new dedicated sniff. #581 - 🚫 PHPCompatibility no longer explicitly supports HHVM and builds are no longer tested against HHVM.
For now, running PHPCompatibility on HHVM to test PHP code may still work for a little while, but HHVM has announced they are dropping PHP support. #623. Fixes #603. - 📚 Readme: badges from services which are no longer supported or inaccurate. #609, #628
Fixed
- 🐛 Previously, the PHPCS native
Generic.NamingConventions.CamelCapsFunctionName
sniff was included in PHPCompatibility. Some error codes of this sniff were excluded, as well as some error messages changed (via the ruleset).
If/when PHPCompatibility would be used in combination with a code style-type ruleset, this could inadvertently lead to underreporting of issues which the CS-type ruleset intends to have reported - i.e. the error codes excluded by PHPCompatibility -. This has now been fixed. #581 - 🐛 The
ForbiddenNegativeBitshift
sniff would incorrectly throw an error when a bitshift was based on a calculation which included a negative number, but would not necessarily result in a negative number. #614. Fixes #294, #466. - 🐛 The
NewClosure
sniff would report the same issue twice when the issue was encountered in a nested closure. #669 - 🐛 The
NewKeywords
sniff would underreport on non-lowercase keywords. #627 - 🐛 The
NewKeywords
sniff would incorrectly report on the use of class constants and class properties using the same name as a keyword. #627 - 🐛 The
NewNullableTypes
sniff would potentially underreport when comments where interspersed in the (return) type declarations. #577 - 🐛 The
Sniff::getFunctionCallParameters()
utility method would in rare cases return incorrect results when it encountered a closure as a parameter. #682 - 🐛 The
Sniff::getReturnTypeHintToken()
utility method would not always return a$stackPtr
. #645 - 🐛 Minor miscellanous other bugfixes. #670
- ☔
PHPCompatibility\Tests\BaseClass\MethodTestFrame::getTargetToken()
could potentially not find the correct token to run a test against. #588
Credits
Thanks go out to Michael Babker and Juliette Reinders Folmer for their contributions to this version. 👏