sirbrillig/phpcs-variable-analysis
PHPCS plugin that analyzes variable usage: warns on undefined variables (including in unset), unused variables, and use of $this/self/static outside class scope. Works with PHPCS 3.13.5+ and PHP 5.4+.
This is preparing for a major 3.0 release which adds a dependency on PHPCSUtils. The new version should have the same functionality, fix some subtle bugs, and increase performance by over 2x.
getUseIndexForUseImport using findContainingOpeningBracket().findFunctionCallArguments custom loop with PassedParameters::getParameters().isConstructorPromotion manual scan with FunctionDeclarations::getParameters().areAnyConditionsAClass manual loop with Conditions::hasCondition().getListAssignments using Lists::getAssignments.findContainingOpeningBracket with the PHPCSUtils equivalent.isVariableInsideUnset/isVariableInsideIssetOrEmpty with PHPCSUtils equivalents.T_FN.isArrowFunction block in getScopeCloseForScopeOpen.sitePassByRefFunctions (#351).compact inside arrow functions (#339).else (#306).readonly constructor promotion (#294).static variable regression from #267.Bug fix release for two regressions caused by the new static function variable scanning added in #267.
for loop increment expression to use a variable defined inside the loop (#262).if list destructure (#268).php_errormsg from superglobals list (#269).else blocks (#239).allowUnusedVariablesInFileScope option (#229).foreach loop variable as a read (#221).A large release that backports nearly all the improvements made on the 3.0 branch to the 2.x line, with the major exception of adding PHPCSUtils as a dependency.
Notable changes since 2.9:
array_walk pass-by-reference in 2.x (#216).isset and empty (#204).if/else (#199).allowUndefinedVariablesInFileScope option (#193).allowUnusedVariablesBeforeRequire option (#196).validUndefinedVariableRegexp option (#173).else blocks (#189).Note: this release intentionally excludes breaking changes from the 3.0 branch, namely replacing UnusedVariable with UnusedParameter for parameters (#195) and adding sniff codes for the array assignment shortcut (#205).
Backports some 3.x features to the 2.x line.
allowUnusedVariablesBeforeRequire option (originally #196).allowUndefinedVariablesInFileScope option (originally #193).A backport of the bugfixes from 3.0.0-beta.1 into the 2.x version without any of the PHPCSUtils changes.
foreach loops with option (#167).A small bug fix release with test and package clean-up.
$this in nested function declaration (#119).self/static within an anonymous class (#110).require (#106), update DealerDirect Composer plugin requirement (#112).composer.lock file (#117).apcu_* functions to getPassByReferenceFunctions (#103).get_defined_vars() to be a read (#92).self and static references in a trait (#76).allowUnusedForeachVariables and allowUnusedCaughtExceptions (#73).foreach option (#66).self within class method closures (#70).allowWordPressPassByRefFunctions option (#69).allowUnusedParametersBeforeUsed default to true (#59).allowUnusedParametersBeforeUsed option (#58).use() constructs (#54).parent keyword as a static reference (#44).foreach variable identification (#36). Fixes a major regression caused by #35.⚠️ DO NOT USE THIS VERSION, IT HAS A MAJOR REGRESSION FIXED IN 2.0.7.
foreach (#35).$this (#25).Lib directory and namespace (#28).$this in closures (#20).roave/security-advisories dependency because it required developers to add additional lines to their composer.json.How can I help you explore Laravel packages today?