Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into t-bad-character
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Feb 6, 2024
2 parents ffdb53e + 8f663b6 commit 1f0b5f8
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To start contributing, fork the repository, create a new branch in your fork, ma

Please make sure that your pull request contains unit tests covering what's being addressed by it.

* All code should be compatible with PHPCS >= 3.7.1.
* All code should be compatible with PHPCS >= 3.8.0.
* All code should be compatible with PHP 5.4 to PHP nightly.
* All code should comply with the PHPCompatibility coding standards.
The [ruleset used by PHPCompatibility](https://github.com/PHPCSStandards/PHPCSDevCS) is largely based on PSR-12 with minor variations and some additional checks for array layout and documentation and such.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:

include:
- php: '7.2'
phpcs_version: '^3.7.1'
phpcs_version: '^3.8.0'
custom_ini: true
experimental: false

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Also as of this version, [Juliette Reinders Folmer] is now officially a co-maint
### Upgrade instructions

* If you have `<exclude name="..."/>` directives in your own project's custom ruleset which relate to sniffs from the PHPCompatibility library, you will need to update your ruleset to use the new sniff names.
* If you use the new [PHPCS 3.2+ inline annotations](https://github.com/squizlabs/PHP_CodeSniffer/releases/3.2.0), i.e. `// phpcs:ignore Standard.Category.SniffName`, in combination with PHPCompatibility sniff names, you will need to update these annotations.
* If you use the new [PHPCS 3.2+ inline annotations](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/3.2.0), i.e. `// phpcs:ignore Standard.Category.SniffName`, in combination with PHPCompatibility sniff names, you will need to update these annotations.
* If you use neither of the above, you should be fine and upgrading should be painless.

### Overview of all the sniff renames:
Expand Down
2 changes: 1 addition & 1 deletion PHPCompatibility/AbstractFunctionCallParameterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function process(File $phpcsFile, $stackPtr)

if (Context::inAttribute($phpcsFile, $stackPtr) === true) {
// Class instantiation or constant in attribute, not function call.
return false;
return;
}

$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
Expand Down
20 changes: 0 additions & 20 deletions PHPCompatibility/Sniffs/Constants/NewConstantsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7830,26 +7830,6 @@ class NewConstantsSniff extends Sniff
'8.3' => true,
'extension' => 'pgsql',
],
'PGSQL_PIPELINE_SYNC' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'PGSQL_PIPELINE_ON' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'PGSQL_PIPELINE_OFF' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'PGSQL_PIPELINE_ABORTED' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'PGSQL_SHOW_CONTEXT_NEVER' => [
'8.2' => false,
'8.3' => true,
Expand Down
25 changes: 0 additions & 25 deletions PHPCompatibility/Sniffs/FunctionUse/NewFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4943,31 +4943,6 @@ class NewFunctionsSniff extends Sniff
'8.3' => true,
'extension' => 'pgsql',
],
'pg_enter_pipeline_mode' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'pg_exit_pipeline_mode' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'pg_pipeline_sync' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'pg_pipeline_status' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'pg_send_flush_request' => [
'8.2' => false,
'8.3' => true,
'extension' => 'pgsql',
],
'posix_sysconf' => [
'8.2' => false,
'8.3' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ public function process(File $phpcsFile, $stackPtr)
}

for ($i = ($openParenthesis + 1); $i < $tokens[$openParenthesis]['parenthesis_closer']; $i++) {
// Ignore anything within square brackets (array access keys).
if (isset($tokens[$i]['bracket_closer'])) {
$i = $tokens[$i]['bracket_closer'];
continue;
}

if ($tokens[$i]['code'] !== \T_VARIABLE || $tokens[$i]['content'] !== '$this') {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public static function dataNewUnionTypes()
['MyClassA|\Package\MyClassB', 80],
['array|bool|int|float|NULL|object|string', 81],
['false|mixed|self|parent|iterable|Resource', 84],
['callable||void', 87, false],
['callable|void', 87, false],
['?int|float', 90],
['bool|FALSE', 99],
['object|ClassName', 102],
Expand Down
8 changes: 4 additions & 4 deletions PHPCompatibility/Tests/Constants/NewConstantsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1561,10 +1561,10 @@ echo POSIX_PC_SYMLINK_MAX;
echo PGSQL_SHOW_CONTEXT_NEVER;
echo PGSQL_SHOW_CONTEXT_ERRORS;
echo PGSQL_SHOW_CONTEXT_ALWAYS;
echo PGSQL_PIPELINE_SYNC;
echo PGSQL_PIPELINE_ON;
echo PGSQL_PIPELINE_OFF;
echo PGSQL_PIPELINE_ABORTED;




echo CURLINFO_CAPATH;
echo CURLINFO_CAINFO;
echo CURLOPT_MIME_OPTIONS;
Expand Down
4 changes: 0 additions & 4 deletions PHPCompatibility/Tests/Constants/NewConstantsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1633,10 +1633,6 @@ public static function dataNewConstant()
['PGSQL_SHOW_CONTEXT_NEVER', '8.2', 1561, '8.3'],
['PGSQL_SHOW_CONTEXT_ERRORS', '8.2', 1562, '8.3'],
['PGSQL_SHOW_CONTEXT_ALWAYS', '8.2', 1563, '8.3'],
['PGSQL_PIPELINE_SYNC', '8.2', 1564, '8.3'],
['PGSQL_PIPELINE_ON', '8.2', 1565, '8.3'],
['PGSQL_PIPELINE_OFF', '8.2', 1566, '8.3'],
['PGSQL_PIPELINE_ABORTED', '8.2', 1567, '8.3'],
['CURLINFO_CAPATH', '8.2', 1568, '8.3'],
['CURLINFO_CAINFO', '8.2', 1569, '8.3'],
['CURLOPT_MIME_OPTIONS', '8.2', 1570, '8.3'],
Expand Down
5 changes: 0 additions & 5 deletions PHPCompatibility/Tests/FunctionUse/NewFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,4 @@ posix_pathconf();
posix_fpathconf();
posix_eaccess();
pg_set_error_context_visibility();
pg_enter_pipeline_mode();
pg_exit_pipeline_mode();
pg_pipeline_sync();
pg_pipeline_status();
socket_atmark();
pg_send_flush_request();
7 changes: 1 addition & 6 deletions PHPCompatibility/Tests/FunctionUse/NewFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,12 +1110,7 @@ public static function dataNewFunction()
['posix_fpathconf', '8.2', 1049, '8.3'],
['posix_eaccess', '8.2', 1050, '8.3'],
['pg_set_error_context_visibility', '8.2', 1051, '8.3'],
['pg_enter_pipeline_mode', '8.2', 1052, '8.3'],
['pg_exit_pipeline_mode', '8.2', 1053, '8.3'],
['pg_pipeline_sync', '8.2', 1054, '8.3'],
['pg_pipeline_status', '8.2', 1055, '8.3'],
['pg_send_flush_request', '8.2', 1057, '8.3'],
['socket_atmark', '8.2', 1056, '8.3'],
['socket_atmark', '8.2', 1052, '8.3'],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ enum Suit: string implements Colorful
}
}

// Issue #1666 - $this in unset, but not being unset.
class NotUnsettingThis {
public function delete() {
unset($array[get_array_key($this)]); // OK.
}
}

/*
* ====================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public static function dataNoFalsePositivesUnset()
[92],
[100],
[101],
[174],
];
}

Expand Down Expand Up @@ -437,7 +438,10 @@ public static function dataNoFalsePositivesOutsideObjectContext()
[133],
[138],
[164],
[219], // Exception to the rule / static __call() magic method.

// Exception to the rule / static __call() magic method.
[224],
[225],
];
}

Expand All @@ -452,7 +456,7 @@ public function testNoFalsePositivesUncovered()
$file = $this->sniffFile(__FILE__, '7.1');

// No errors expected on the last group of lines.
for ($line = 172; $line <= 226; $line++) {
for ($line = 178; $line <= 232; $line++) {
$this->assertNoViolation($file, $line);
}
}
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PHP Compatibility Coding Standard for PHP CodeSniffer
[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4%20|%208.0%20|%208.1%20|%208.2%20|%208.3%20|%20nightly%20-brightgreen.svg?maxAge=2419200)](https://github.com/PHPCompatibility/PHPCompatibility/actions?query=workflow%3ATest)


This is a set of sniffs for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) that checks for PHP cross-version compatibility.
This is a set of sniffs for [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) that checks for PHP cross-version compatibility.
It will allow you to analyse your code for compatibility with higher and lower versions of PHP.

* [PHP Version Support](#php-version-support)
Expand Down Expand Up @@ -43,13 +43,13 @@ Requirements
-------

* PHP 5.4+
* PHP CodeSniffer: 3.7.1+.
* PHP CodeSniffer: 3.8.0+.

The sniffs are designed to give the same results regardless of which PHP version you are using to run PHP CodeSniffer. You should get consistent results independently of the PHP version used in your test environment, though for the best results it is recommended to run the sniffs on a recent PHP version in combination with a recent PHP_CodeSniffer version.

As of version 8.0.0, the PHPCompatibility standard can also be used with PHP CodeSniffer 3.x.
As of version 9.0.0, support for PHP CodeSniffer 1.5.x and low 2.x versions < 2.3.0 has been dropped.
As of version 10.0.0, support for PHP < 5.4 and PHP CodeSniffer < 3.7.1 has been dropped.
As of version 10.0.0, support for PHP < 5.4 and PHP CodeSniffer < 3.8.0 has been dropped.


Thank you
Expand All @@ -63,9 +63,9 @@ Thanks to [WP Engine](https://wpengine.com) for their support on the PHP 7.0 sni
--------
This library has been reorganized. All sniffs have been placed in categories and a significant number of sniffs have been renamed.

If you use the complete `PHPCompatibility` standard without `exclude` directives in a custom ruleset and do not (yet) use the new-style PHP_CodeSniffer annotation as introduced in [PHP_CodeSniffer 3.2.0](https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0), this will have no noticeable effect and everything should work as before.
If you use the complete `PHPCompatibility` standard without `exclude` directives in a custom ruleset and do not (yet) use the new-style PHP_CodeSniffer annotation as introduced in [PHP_CodeSniffer 3.2.0](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/tag/3.2.0), this will have no noticeable effect and everything should work as before.

However, if you do use `exclude` directives for PHPCompatibility sniffs in a custom ruleset or if you use the [new-style PHP_CodeSniffer inline annotations](https://github.com/squizlabs/PHP_CodeSniffer/releases/3.2.0), you will need to update these when upgrading. This should be a one-time only change.
However, if you do use `exclude` directives for PHPCompatibility sniffs in a custom ruleset or if you use the [new-style PHP_CodeSniffer inline annotations](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/3.2.0), you will need to update these when upgrading. This should be a one-time only change.
The changelog contains detailed information about all the sniff renames.

Please read the changelog for version [9.0.0](https://github.com/PHPCompatibility/PHPCompatibility/releases/tag/9.0.0) carefully before upgrading.
Expand Down Expand Up @@ -110,7 +110,7 @@ Installation in a Composer project (method 1)
Installation via a git check-out to an arbitrary directory (method 2)
-----------------------

* Install [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) via [your preferred method](https://github.com/squizlabs/PHP_CodeSniffer#installation).
* Install [PHP CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) via [your preferred method](https://github.com/PHPCSStandards/PHP_CodeSniffer#installation).

PHP CodeSniffer offers a variety of installation methods to suit your work-flow: Composer, [PEAR](http://pear.php.net/PHP_CodeSniffer), a Phar file, zipped/tarred release archives or checking the repository out using Git.

Expand All @@ -122,7 +122,7 @@ Installation via a git check-out to an arbitrary directory (method 2)
```bash
phpcs --config-set installed_paths /path/to/PHPCompatibility
```
I.e. if you placed the `PHPCompatibility` repository in the `/my/custom/standards/PHPCompatibility` directory, you will need to add that directory to the PHP CodeSniffer [`installed_paths` configuration variable](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths).
I.e. if you placed the `PHPCompatibility` repository in the `/my/custom/standards/PHPCompatibility` directory, you will need to add that directory to the PHP CodeSniffer [`installed_paths` configuration variable](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths).

**Warning**: :warning: The `installed_paths` command overwrites any previously set `installed_paths`. If you have previously set `installed_paths` for other external standards, run `phpcs --config-show` first and then run the `installed_paths` command with all the paths you need separated by commas, i.e.:
```bash
Expand All @@ -148,7 +148,7 @@ Sniffing your code for compatibility with specific PHP version(s)
- You can also specify a range of PHP versions that your code needs to support. In this situation, compatibility issues that affect any of the PHP versions in that range will be reported: `--runtime-set testVersion 5.3-5.5`.
- As of PHPCompatibility 7.1.3, you can omit one part of the range if you want to support everything above or below a particular version, i.e. use `--runtime-set testVersion 7.0-` to run all the checks for PHP 7.0 and above.
* By default the report will be sent to the console, if you want to save the report to a file, add the following to the command line command: `--report-full=path/to/report-file`.
For more information and other reporting options, check the [PHP CodeSniffer wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting).
For more information and other reporting options, check the [PHP CodeSniffer wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting).


### Using a framework/CMS/polyfill specific ruleset
Expand Down Expand Up @@ -191,7 +191,7 @@ You can also set the `testVersion` from within the ruleset:
<config name="testVersion" value="5.6-"/>
```

Other advanced options, such as changing the message type or severity of select sniffs, as described in the [PHPCS Annotated ruleset](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.
Other advanced options, such as changing the message type or severity of select sniffs, as described in the [PHPCS Annotated ruleset](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml) wiki page are, of course, also supported.

### `testVersion` in the ruleset versus command-line

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
},
"require": {
"php": ">=5.4",
"squizlabs/php_codesniffer": "^3.7.1",
"phpcsstandards/phpcsutils": "^1.0.5"
"squizlabs/php_codesniffer": "^3.8.0",
"phpcsstandards/phpcsutils": "^1.0.9"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.3.2",
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

Expand Down

0 comments on commit 1f0b5f8

Please sign in to comment.