Find undefined and unused variables with the PHP Codesniffer static analysis tool.

Overview

PHP_CodeSniffer VariableAnalysis

CircleCI

Plugin for PHP_CodeSniffer static analysis tool that adds analysis of problematic variable use.

  • Warns if variables are used without being defined. (Sniff code: VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)
  • Warns if variables are used inside unset() without being defined. (Sniff code: VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedUnsetVariable)
  • Warns if variables are set or declared but never used. (Sniff code: VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable)
  • Warns if $this, self::$static_member, static::$static_member is used outside class scope. (Sniff codes: VariableAnalysis.CodeAnalysis.VariableAnalysis.SelfOutsideClass or VariableAnalysis.CodeAnalysis.VariableAnalysis.StaticOutsideClass)

Installation

Requirements

VariableAnalysis requires PHP 5.4 or higher and PHP CodeSniffer version 3.5.0 or higher.

With PHPCS Composer Installer

This is the easiest method.

First, install phpcodesniffer-composer-installer for your project if you have not already. This will also install PHPCS.

composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer require --dev dealerdirect/phpcodesniffer-composer-installer

Then install these standards.

composer require --dev sirbrillig/phpcs-variable-analysis

You can then include the sniffs by adding a line like the following to your phpcs.xml file.

<rule ref="VariableAnalysis"/>

It should just work after that!

Standalone

  1. Install PHP_CodeSniffer (PHPCS) by following its installation instructions (via Composer, Phar file, PEAR, or Git checkout).

    Do ensure that PHP_CodeSniffer's version matches our requirements.

  2. Install VariableAnalysis. Download either the zip or tar.gz file from the VariableAnalysis latest release page. Expand the file and rename the resulting directory to phpcs-variable-analysis. Move the directory to a place where you'd like to keep all your PHPCS standards.

  3. Add the paths of the newly installed standards to the PHP_CodeSniffer installed_paths configuration. The following command should append the new standards to your existing standards (be sure to supply the actual paths to the directories you created above).

     phpcs --config-set installed_paths "$(phpcs --config-show|grep installed_paths|awk '{ print $2 }'),/path/to/phpcs-variable-analysis"
    

    If you do not have any other standards installed, you can do this more easily (again, be sure to supply the actual paths):

     phpcs --config-set installed_paths /path/to/phpcs-variable-analysis
    

Customization

There's a variety of options to customize the behaviour of VariableAnalysis, take a look at the included ruleset.xml.example for commented examples of a configuration.

The available options are as follows:

  • allowUnusedFunctionParameters (bool, default false): if set to true, function arguments will never be marked as unused.
  • allowUnusedCaughtExceptions (bool, default true): if set to true, caught Exception variables will never be marked as unused.
  • allowUnusedParametersBeforeUsed (bool, default true): if set to true, unused function arguments will be ignored if they are followed by used function arguments.
  • allowUnusedVariablesBeforeRequire (bool, default false): if set to true, variables defined before a require, require_once, include, or include_once will not be marked as unused. They may be intended for the required file.
  • allowUndefinedVariablesInFileScope (bool, default false): if set to true, undefined variables in the file's top-level scope will never be marked as undefined. This can be useful for template files which use many global variables defined elsewhere.
  • allowUnusedVariablesInFileScope (bool, default false): if set to true, unused variables in the file's top-level scope will never be marked as unused. This can be helpful when defining a lot of global variables to be used elsewhere.
  • validUnusedVariableNames (string, default null): a space-separated list of names of placeholder variables that you want to ignore from unused variable warnings. For example, to ignore the variables $junk and $unused, this could be set to 'junk unused'.
  • ignoreUnusedRegexp (string, default null): a PHP regexp string (note that this requires explicit delimiters) for variables that you want to ignore from unused variable warnings. For example, to ignore the variables $_junk and $_unused, this could be set to '/^_/'.
  • validUndefinedVariableNames (string, default null): a space-separated list of names of placeholder variables that you want to ignore from undefined variable warnings. For example, to ignore the variables $post and $undefined, this could be set to 'post undefined'. This can be used in combination with validUndefinedVariableRegexp.
  • validUndefinedVariableRegexp (string, default null): a PHP regexp string (note that this requires explicit delimiters) for variables that you want to ignore from undefined variable warnings. For example, to ignore the variables $post and $undefined, this could be set to '/^(post|undefined)$/'. This can be used in combination with validUndefinedVariableNames.
  • allowUnusedForeachVariables (bool, default true): if set to true, unused values from the key => value syntax in a foreach loop will never be marked as unused.
  • sitePassByRefFunctions (string, default null): a list of custom functions which pass in variables to be initialized by reference (eg preg_match()) and therefore should not require those variables to be defined ahead of time. The list is space separated and each entry is of the form functionName:1,2. The function name comes first followed by a colon and a comma-separated list of argument numbers (starting from 1) which should be considered variable definitions. The special value ... in the arguments list will cause all arguments after the last number to be considered variable definitions.
  • allowWordPressPassByRefFunctions (bool, default false): if set to true, a list of common WordPress pass-by-reference functions will be added to the list of PHP ones so that passing undefined variables to these functions (to be initialized by reference) will be allowed.

To set these these options, you must use XML in your ruleset. For details, see the phpcs customizable sniff properties page. Here is an example that ignores all variables that start with an underscore:

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
    <properties>
        <property name="ignoreUnusedRegexp" value="/^_/"/>
    </properties>
</rule>

See Also

  • ImportDetection: A set of phpcs sniffs to look for unused or unimported symbols.
  • phpcs-changed: Run phpcs on files, but only report warnings/errors from lines which were changed.

Original

This was forked from the excellent work in https://github.com/illusori/PHP_Codesniffer-VariableAnalysis

Contributing

Please open issues or PRs on this repository.

Any changes should be accompanied by tests and should pass linting and static analysis. Please use phpdoc (rather than actual types) for declaring types since this must run in PHP 5.4.

To run tests, make sure composer is installed, then run:

composer install # you only need to do this once
composer test

To run linting, use:

composer lint

To run static analysis, use:

composer phpstan
Comments
  • Improve errorcode differentiation

    Improve errorcode differentiation

    function foo($paramUnusedBeforeUsed, $paramUsed, $paramUnused) {
        $index = 1;
        echo $paramUsed;
    }
    

    Both the unused $paramUnusedBeforeUsed and $paramUnused as well as the unused $index currently have the same error code: UnusedVariable.

    While I realize that the allowUnusedFunctionParameters and allowUnusedParametersBeforeUsed properties exist, those can only be set for a complete code base, while differentiation via error codes gives more control, i.e. you can include/exclude select files for certain error codes.

    <rule ref="VariableAnalysis"/>
    <rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.ErrorCode">
        <exclude-pattern>/src/specific-directory/*\.php$</exclude-pattern>
        <exclude-pattern>/src/specific-file\.php$</exclude-pattern>
    </rule>
    

    Unused parameters cannot always be "solved" as the method signature of a class method where the class extends a parent and/or implements an interface, has to be compatible with the parent class/interface.

    Unused variables defined within a function is another matter.

    With that in mind, I'd like to propose to split the UnusedVariable error code into three distinct error codes:

    • UnusedParameterBeforeUsed
    • UnusedParameter[AfterUsed]
    • UnusedVariable

    This would also pave the way to removing the allowUnusedFunctionParameters and allowUnusedParametersBeforeUsed properties.

    As the next version is intended to be a major tag, now would probably be a good time to make such a change.

    To make the BC-break smaller, I'd like to suggest for the properties to be deprecated in this major and only removed in the next major release.

    For the time being, the properties could then still be checked to determine whether the UnusedParameter... errors should be thrown or not, giving people some time to switch over to using the error code exclusion instead of the properties.

    enhancement 
    opened by jrfnl 17
  • Unused function parameters are not always found

    Unused function parameters are not always found

    Hi

    Yesterday when testing VA, I found that unused function parameters are not always discovered. Here is the corresponding code part:

    	private function get_hidden_span($user_type, $text, $testvar)
    	{
    		global $config;
    		
    		if (!$config['lfwwh_create_hidden_info'])
    		{
    			return '';
    		}
    		return '<span class="lfwwh_info_' . (($user_type != USER_IGNORE || $config['lfwwh_disp_bots'] == 1) ? 'u' : 'b') . '" style="display: none;">' . $text . '</span>';
    	}
    

    VA should actually find $testvar here, which is not the case. After many attempts, I found that VA found this variable when the allowUnusedParametersBeforeUsed switch was set to 0.

    There would be other code examples if desired.

    bug 
    opened by LukeWCS 15
  • False positive for unused variable when variable is passed by reference in closure

    False positive for unused variable when variable is passed by reference in closure

    DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable gives a false positive for the $uri variable in the following example:

    \Drupal::httpClient()->get($input, [
      'on_stats' => function (TransferStats $stats) use (&$uri) {
        $uri = $stats->getEffectiveUri();
      },
    ]);
    

    Another false positive occurs for the following code snippet which modifies an array by reference:

     80 | WARNING | Unused variable $entry.
        |         | (DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable)
    
    foreach ($derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }
    

    The sniff doesn't detect that the $uri variable is actually in use since it is passed by reference to the anonymous function.

    Originally posted in https://www.drupal.org/project/coder/issues/3065679.

    opened by MPParsley 11
  • Unit test: fix tests failing

    Unit test: fix tests failing

    I'm not completely sure why, but when I tried to run the unit tests locally, most were failing.

    This minor tweak in how PHPCS is instantiated fixes it. It also removes the need for the getSniffFiles() method as there is only one sniff in this standard anyway.

    opened by jrfnl 11
  • Unexpected unused variable warning in subclass method since v2.8.2

    Unexpected unused variable warning in subclass method since v2.8.2

    I have a base class like this:

    abstract class Shortcode {
    
    	abstract public static function callback( $attrs, $content = '' );
    }
    

    And a subclass like this:

    class Thumbnail_Gallery extends Shortcode {
    
    	public static function callback( $attrs, $content = '' ) {
    		return '';
    	}
    }
    

    Since v2.8.2, $attrs and $content are (unexpectedly?) flagged as unused variables. However, removing them causes a fatal error.

    opened by danielbachhuber 10
  • Direct variable-as-array assignment marked as undefined

    Direct variable-as-array assignment marked as undefined

    You do not need to register/create a variable before assigning indexes. Instead, you can directly create a variable as an array. You can also see this in PHP's array example 12.

    $a['index'] = 'value';
    print_r( $a ); // Array ( [index] => value )
    
    $b[] = 'value';
    print_r( $b ); // Array ( [0] => value )
    
    $c['index'][]['deep'] = 'value';
    print_r( $c ); // Array ( [index] => Array ( [0] => Array ( [deep] => value ) ) )
    

    However, this warning is thrown at the variable assignment, and whenever later you reuse the variable:

    Variable $a is undefined.
    (VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)
    

    Now, do keep in mind that PHP's documentation doesn't explicitly state if and why this would work. So, whether this is a best practice or not is up for debate, but I don't think this specific warning should be thrown—it should be mitigated elsewhere.

    As for examples in the wild, I found one in WordPress:

    • https://github.com/WordPress/WordPress/blob/7112ee71329533c9a168e4736582f537e30f7068/wp-admin/edit-comments.php#L286
    enhancement 
    opened by sybrew 10
  • Unused global variable warning when global variable is written to

    Unused global variable warning when global variable is written to

    Say I have this function:

    function updateGlobal($newVal) {
      global $myGlobal;
      $myGlobal = $newVal;
    }
    

    I will get the following message:

    Unused global variable $myGlobal.

    It seems like this is an erroneous message. Or at least it should be configurable.

    Currently, I'm able to get around the warning this way:

    function updateGlobal($newVal) {
      global $myGlobal;
      $myGlobal;
      $myGlobal = $newVal;
    }
    

    But this is not ideal.

    bug 
    opened by aeisenberg 10
  • Support marking some function arguments as unused

    Support marking some function arguments as unused

    Take the following code as an example:

    <?php
    namespace Whatever;
    
    use Symfony\Component\HttpKernel\Exception\HttpException;
    use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
    use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
    
    final class LumenExceptionHandler extends ExceptionHandler {
        public function render($request, \Exception $e) {
            $status = 500;
            if ($e instanceof HttpExceptionInterface) {
                $status = $e->getStatusCode();
            }
    
            return response()->json(['message' => $e->getMessage()], $status);
        }
    }
    

    The render function takes 2 arguments. A request and an exception. We have to accept these two arguments because we're overwriting a method and we want to match it's signature.

    In our implementation, we don't actually care about the $request param. PHPCS gives me a warning because $request is unused.

    I want to be able to tell PHPCS that this argument is unused and that this is OK.

    With Rubocop (a ruby linter), I can prefix an argument with _ to mark it as unused and to let the linter know that this is OK. Here's the relevant doc: https://rubocop.readthedocs.io/en/latest/cops_lint/#lintunusedmethodargument

    We could have something like this:

    public function render($_request, \Exception $e) {
      // ...
    }
    

    This would not generate any warnings since we've explicitly said that the argument should be unused.

    enhancement 
    opened by dotboris 10
  • GH Actions: various updates

    GH Actions: various updates

    GH Actions: fix use of deprecated set-output

    GitHub has deprecated the use of set-output (and set-state) in favour of new environment files.

    This commit updates workflows to use the new methodology.

    Refs:

    • https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
    • https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files

    ~~GH Actions: update the xmllint-problem-matcher~~

    ~~The xmllint-problem-matcher action runner has released a new version which updates it to use node 16. This gets rid of a warning which was shown in the action logs.~~

    ~~Note: I've suggested to the author to use long-running branches for the action runner instead, which would make this update redundant, but no telling if or when they'll respond to that, let alone if they will follow my suggestion.~~

    Refs:

    • https://github.com/korelstar/xmllint-problem-matcher/releases/tag/v1.1

    🆕 GH Actions: harden the workflow against PHPCS ruleset errors

    If there is a ruleset error, the cs2pr action doesn't receive an xml report and exits with a 0 error code, even though the PHPCS run failed (though not on CS errors, but on a ruleset error).

    This changes the GH Actions workflow to allow for that situation and still fail the build in that case.


    👉🏻 Note: this won't get rid of all warning yet as a lot of predefined action runners also use set-output, but most of those are in the process of updating and/or have released a new version already, so the other warnings should automatically disappear over the next few weeks.

    opened by jrfnl 8
  • False positives

    False positives

    After upgrading from v2.9.0 to v2.10.2 I got a lot of false positives and I had to downgrade again. For example:

    $var = NULL;
    
    function foo(){
        global $var;
        // var used here
    }
    

    causes a VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable.

    Also

    if(($val = func()) !== FALSE){
        $val->foo();
    }
    

    causes a VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable.

    opened by djibarian 8
  • Mixing concatenating assignment operator and assigment operation results in false positive.

    Mixing concatenating assignment operator and assigment operation results in false positive.

    Given the following code

      $suggestion = 'block';
      while ($part = array_shift($parts)) {
        $suggestions[] = $suggestion .= '__' . strtr($part, '-', '_');
      }
    

    $suggestion will be marked as unused.

    bug 
    opened by alexpott 8
  • Add validUndefinedVariableNamesInFileScope

    Add validUndefinedVariableNamesInFileScope

    Where a variable is available within the File scope, it will not be available within a function scope without the use of global $varname;.

    At the moment it's possible to either set:

    • validUndefinedVariableNames, but this will incorrectly apply within function scope where the variable is not available to be used; or
    • allowUndefinedVariablesInFileScope, but this is an on/off value and may not be accurate.

    It should be possible to define which variables are allowed to be used within the file scope.

    enhancement 
    opened by andrewnicols 1
  • Reduce use of array_... functions

    Reduce use of array_... functions

    As reported in https://github.com/sirbrillig/phpcs-variable-analysis/pull/234

    Array functions like array_merge() and array_values() are "expensive".

    opened by sirbrillig 0
  • ETA v3?

    ETA v3?

    Hey,

    Do you have an ETA for when v3 can have a stable tag? arrow functions are not possible if I recall correctly due to constrains in this package

    Regards, Levi

    opened by Levivb 23
  • Sniff for detecting single-use variables?

    Sniff for detecting single-use variables?

    Trying to avoid this example BAD (due to refactoring, or simple human error):

    $has_free_tag = has_tag( 'free' );
    
    if ( $has_free_tag ) {
      ...
    }
    

    BETTER:

    if ( has_tag( 'free' ) ) {
      ...
    }
    
    enhancement help wanted 
    opened by lkraav 1
  • Assignment by reference is not declaration for arrays and objects

    Assignment by reference is not declaration for arrays and objects

    function whileLooopAssignWithUndefinedShift() {
      $suggestions = [];
      while ($part = array_shift($parts)) { // undefined variable parts
        $suggestions[] = $part;
      }
      return $suggestions;
    }
    

    $parts is not marked as undefined. This is happening because array_shift counts as an assignment... but clearly not all assignments should be counted as definitions if the expected variable is an array or object.

    This may mean that we need to annotate all the pass-by-reference functions in both PHP and WordPress by what types of variables they expect. 😩

    bug 
    opened by sirbrillig 1
  • Allow for functions which set variables in the current scope

    Allow for functions which set variables in the current scope

    In PHP there are a number of functions which can set variables in the current scope. Sometimes by reference to a passed parameter (first examples), sometimes just plainly in the current scope (second examples).

    While the first set of examples is handled correctly by the sniff, the second set of examples is not.

    Now, I'm not saying it will be easy to handle this or that I have a ready-made solution for this, but I figured opening an issue as a reminder to have a look at this at some point would be a good idea nevertheless.

    1. Functions setting a variable by reference.

    	parse_str($str, $output);
    	echo $output['first']; 
    
    	preg_match('`.*`', $first, $matches);
    	var_dump($matches);
    

    The sniff correctly doesn't throw an error for $matches or $output being used.

    2. Functions setting variables in the current scope.

    function foo() {
    	$str = "first=value&second=value&arr[]=foo+bar&arr[]=baz";
    	parse_str($str);
    	echo $first;  // value
    	echo $second;  // value
    	echo $arr[0]; // foo bar
    	echo $arr[1]; // baz
    	
    	$array = [
    		'a' => 1,
    		'b' => 'test',
    	];
    	extract($array);
    	echo $a, $b;
    }
    

    The sniff as-is will throw errors for use of "undefined" $first, $second, $arr, $a, $b variables, while these are in actual fact all defined.

    bug 
    opened by jrfnl 3
Releases(v2.11.9)
  • v2.11.9(Oct 5, 2022)

  • v2.11.8(Sep 8, 2022)

  • v2.11.7(Aug 16, 2022)

    Changelog

    Another bug fix for a static variable regression caused by https://github.com/sirbrillig/phpcs-variable-analysis/pull/267.

    • Place static arrow function body outside of scope on static declaration check (#276) Props @arkener!
    Source code(tar.gz)
    Source code(zip)
  • v2.11.6(Aug 15, 2022)

    Changelog

    This is a bug fix release for two regressions caused by the new static function variable scanning added in #267.

    • Ignore function call arguments on static declarations processing (#273) props @arkener!
    • Fix scanning for static variables near start of file (#274)
    Source code(tar.gz)
    Source code(zip)
  • v2.11.5(Aug 14, 2022)

    Changelog

    • Allow for loop increment expression to use variable defined inside loop (#262)
    • Support constructor promotion (#266)
    • Improve static declaration checks (#267)
    • Handle inline if list destructure (#268)
    • Remove php_errormsg from superglobals list (#269)
    • Ignore unused parameters when function in abstract class is empty (#270)
    Source code(tar.gz)
    Source code(zip)
  • v2.11.4(Jul 21, 2022)

  • v2.11.3(Feb 21, 2022)

  • v2.11.2(Jul 6, 2021)

  • v2.11.1(Jun 18, 2021)

  • v2.11.0(Mar 15, 2021)

  • v2.10.3-beta.1(Mar 9, 2021)

  • v2.10.2(Jan 18, 2021)

    Changelog

    • Treat writing to a by-reference foreach loop variable as a read (#221) (props to @MPParsley for finding this bug!)
    • Properly detect variables used in quotes inside arrow functions (#222) (props to @ocean90 for finding this bug!)
    Source code(tar.gz)
    Source code(zip)
  • v2.10.2-beta.1(Dec 30, 2020)

    Changelog

    • Treat writing to a by-reference foreach loop variable as a read (#221) (props to @MPParsley for finding this bug!)
    • Properly detect variables used in quotes inside arrow functions (#222) (props to @ocean90 for finding this bug!)
    Source code(tar.gz)
    Source code(zip)
  • v2.10.1(Dec 12, 2020)

    Changelog

    This is just a performance enhancement for certain nested list detection. In at least one example file, this brings the speed from 7 minutes down to 0.3 seconds. 😱

    • Only check one parent for recursive list assignment (#218)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta.8(Nov 23, 2020)

  • v2.10.0(Dec 5, 2020)

    Changelog

    This is a pretty large release which backports nearly all the improvements that have been made to the 3.0 branch back to the 2.x line, with the major exception of adding phpcsutils as a dependency (which will still be done in 3.0 and will improve accuracy and reduce the amount of code needed by this sniff when it is released).

    Notable changes from 2.9 include:

    • Fix array_walk pass-by-reference in 2.x (#216)
    • Support for PHP 7.4 arrow functions. (#179)
    • Rewritten and more accurate scope detection.
    • Allow undefined variables inside isset and empty (#204)
    • Fix error in closures with namespace separators (#197)
    • Fix complex default arguments (#198)
    • Handle inline if/else (#199)
    • Add allowUndefinedVariablesInFileScope option (#193)
    • Add allowUnusedVariablesBeforeRequire option (#196)
    • Support global scope (#190)
    • Add validUndefinedVariableRegexp option (#173) <Rubén Gómez>
    • Refactor and clean up reference variables (#187)
    • Add special cases for variables used in else blocks (#189)

    Changes that this does not include (since they are breaking changes):

    • Replace UnusedVariable with UnusedParameter for parameters (#195)
    • Add sniff codes for array assignment shortcut (#205)
    Source code(tar.gz)
    Source code(zip)
  • v2.10.0-beta.3(Nov 23, 2020)

  • v2.10.0-beta.1(Nov 10, 2020)

    Changelog

    This is a pretty large release which backports nearly all the improvements that have been made to the 3.0 branch back to the 2.x line, with the major exception of adding phpcsutils as a dependency (which will still be done in 3.0 and will improve accuracy and reduce the amount of code needed by this sniff when it is released).

    Notable changes from 2.9 include:

    • Support for PHP 7.4 arrow functions. (#179)
    • Rewritten and more accurate scope detection.
    • Allow undefined variables inside isset and empty (#204)
    • Fix error in closures with namespace separators (#197)
    • Fix complex default arguments (#198)
    • Handle inline if/else (#199)
    • Add allowUndefinedVariablesInFileScope option (#193)
    • Add allowUnusedVariablesBeforeRequire option (#196)
    • Support global scope (#190)
    • Add validUndefinedVariableRegexp option (#173) <Rubén Gómez>
    • Refactor and clean up reference variables (#187)
    • Add special cases for variables used in else blocks (#189)

    Changes that this does not include (since they are breaking changes):

    • Replace UnusedVariable with UnusedParameter for parameters (#195)
    • Add sniff codes for array assignment shortcut (#205)
    Source code(tar.gz)
    Source code(zip)
  • v2.9.0(Oct 7, 2020)

    Changelog

    This release backports some 3.x features back to the 2.x line.

    • Add allowUnusedVariablesBeforeRequire option (originally #196)
    • Add allowUndefinedVariablesInFileScope option (originally #193)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta.7(Sep 15, 2020)

    Changelog

    • Allow undefined variables inside isset and empty (#204)
    • Replace UnusedVariable with UnusedParameter for parameters (#195)
    • Add sniff codes for array assignment shortcut (#205)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta.6(Sep 2, 2020)

  • v3.0.0-beta.5(Aug 24, 2020)

  • v3.0.0-beta.4(Aug 18, 2020)

    Changelog

    • Downgrade requirements from PHP 5.6 to 5.4 (#191)
    • Add validUndefinedVariableRegexp to README (#192)
    • Add allowUndefinedVariablesInFileScope option (#193)
    • Fix example ruleset (#194)
    • Add allowUnusedVariablesBeforeRequire option (#196)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta.3(Jul 11, 2020)

  • v2.8.3(Jul 11, 2020)

  • v3.0.0-beta.2(Jul 10, 2020)

    Changelog

    • Added property validUndefinedVariableRegexp to VariableAnalysisSniff (#173) <Rubén Gómez>
    • Add arrow function support (#179)
    • Refactor and clean up reference variables (#187)
    • Add special cases for variables used in else blocks (#189)
    Source code(tar.gz)
    Source code(zip)
  • v2.8.2(May 31, 2020)

    Changelog

    This is a backport of the bugfixes from 3.0.0-beta.1 into the 2.x version without any of the PHPCSUtils changes.

    • Fix comment tolerance for many sniffs (huge props to @jrfnl)
    • Clean up package structure (@jrfnl also, for the most part)
    • Only allow unused values in associative foreach loops with option (#167)
    • Fix unused-before-used detection (#171)
    Source code(tar.gz)
    Source code(zip)
  • v2.8.2-beta.1(May 25, 2020)

    Changelog

    This is a backport of the bugfixes in 3.0.0-beta.1 into the 2.x version without any of the PHPCSUtils changes. Because of the nature of a backport, this is a test release to make sure everything works properly before I do a proper release of 2.8.2.

    • Fix comment tolerance for many sniffs (huge props to @jrfnl)
    • Clean up package structure (@jrfnl also, for the most part)
    • Only allow unused values in associative foreach loops with option (#167)
    • Fix unused-before-used detection (#171)
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta.1(May 12, 2020)

    Changelog

    This is a beta release of 3.0. The breaking change is that we now require an external library which is installed by composer. Before release we'll need to update the documentation about how to do a stand-alone install (see #160) and ideally add support for PHP 7.4 (see #165).

    Source code(tar.gz)
    Source code(zip)
  • v2.8.1(Feb 11, 2020)

    Changelog

    This is a small bug fix release with a bunch of test and package clean-up from brave contributors @jrfnl and @alexpott. Thanks, friends! ❤️

    • Make assignment of a reference variable be considered a use (#128)
    • Bug fix: false negative unused var (#120)
    • PHPStan: document run parameters in project ruleset (#122)
    • Composer: update PHPCS Composer plugin dependency (#121)
    • Bug fix: $this in nested function declaration (#119)
    • Documentation: minor fixes (#123)
    • Remove stray composer.lock file (#117)
    • Tests: simplify the PHPCS setup method [1] (#115)
    • Composer: make the PHPUnit requirements more flexible (#114)
    • Tests: allow them to work cross-platform (#108)
    • Composer: update DealerDirect Composer plugin requirement (#112)
    • PHPCS: document run parameters in project ruleset (#107)
    • PHPUnit config: add testsuite name (#113)
    • Bug fix: recognize use of self/static within anonymous class (#110)
    • Composer: move PHPCS dependency to require (#106)
    Source code(tar.gz)
    Source code(zip)
Owner
Payton Swick
Vegan. Digital craftsman. Tea explorer. Avid learner of things. Writes code @automattic.
Payton Swick
Preferences are configuration variables that are user-managed for which we cannot rely upon container parameters or environment variables.

Preferences Preferences are configuration variables that are meant to be user managed for which we cannot rely upon container parameters or environmen

Makina Corpus 1 Feb 7, 2022
Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Magento ECG 309 Jan 3, 2023
Find forgotten variables dump in PHP source code.

PHP VarDump Check This repository is abandoned. Suggested alternative: https://github.com/php-parallel-lint/PHP-Var-Dump-Check PHP console application

Jakub Onderka 27 Jul 13, 2022
Find forgotten variables dump in PHP source code.

PHP VarDump Check PHP console application for find forgotten variable dump. Support PHP build in method print_r, var_dump and var_export method and al

PHP Parallel lint 13 Jul 13, 2022
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

PhpMetrics 2.3k Jan 5, 2023
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

?? Yell PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects. Requirement

Zeeshan Ahmad 20 Dec 8, 2018
A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

A pure PHP implementation of the open Language Server Protocol. Provides static code analysis for PHP for any IDE.

Felix Becker 1.1k Jan 4, 2023
WooCommerce function and class declaration stubs for static analysis.

WooCommerce Stubs This package provides stub declarations for WooCommerce functions, classes and interfaces. These stubs can help plugin and theme dev

PHP Stubs Library 54 Dec 27, 2022
Docker image that provides static analysis tools for PHP

Static Analysis Tools for PHP Docker image providing static analysis tools for PHP. The list of available tools and the installer are actually managed

Jakub Zalas 1.1k Jan 1, 2023
Attributes to define PHP language extensions (to be enforced by static analysis)

PHP Language Extensions (currently in BETA) This library provides attributes for extending the PHP language (e.g. adding package visibility). The inte

Dave Liddament 70 Dec 19, 2022
Perform static analysis of Drupal PHP code with phpstan-drupal.

Perform static analysis of Drupal PHP code with PHPStan and PHPStan-Drupal on Drupal using PHP 8. For example: docker run --rm \ -v $(pwd)/example01

Dcycle 0 Dec 10, 2021
Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

null 48 Jan 5, 2023
This plugin help us to remove the unused file or directories in vendor

Composer Ignore Plugin This plugin help us to remove the unused file or directories in vendor. Installation Both global or local install can work well

__FresHmaN 21 Oct 21, 2021
This is a library to serialize PHP variables in JSON format

This is a library to serialize PHP variables in JSON format. It is similar of the serialize() function in PHP, but the output is a string JSON encoded. You can also unserialize the JSON generated by this tool and have you PHP content back.

Zumba 118 Dec 12, 2022
A simple library to increase the power of your environment variables.

Environment A simple library (with all methods covered by php unit tests) to increase the power of your environment variables, contribute with this pr

João Paulo Cercal 56 Feb 8, 2022
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
Magento 2 Megamenu extension is an indispensable component, and plays the role of website navigation to help customers easily categorize and find information

Mageno 2 Mega Menu (Magicmenu) helps you create neat and smart navigation menus to display the main categories on your website.

https://magepow.com 35 Dec 1, 2022
A Tinder-like experience for Plex Watchlist: swipe and match with another person and find the movie you're gonna watch tonight.

Plex Finder This app's goal is to help choose a film to watch when neither you nor your SO/friend/roommate/whatever is any good at choosing anything.

Guillaume Hartemann-Piollet 3 Aug 13, 2022