Skip to content

Commit e74812a

Browse files
authored
Merge pull request #448 from PHPCSStandards/develop
Release 1.0.2
2 parents 4fd2e30 + f1ddb82 commit e74812a

40 files changed

+800
-194
lines changed

.github/workflows/quicktest.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
strategy:
3535
matrix:
3636
php: ['5.4', 'latest']
37-
phpcs_version: ['3.7.1', 'dev-master']
37+
phpcs_version: ['lowest', 'dev-master']
3838

3939
name: "QTest${{ matrix.phpcs_version == 'dev-master' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
4040

@@ -60,8 +60,9 @@ jobs:
6060
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
6161
coverage: none
6262

63-
- name: 'Composer: set PHPCS version for tests'
64-
run: composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}"
63+
- name: "Composer: set PHPCS version for tests (master)"
64+
if: ${{ matrix.phpcs_version != 'lowest' }}
65+
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
6566

6667
# Install dependencies and handle caching in one go.
6768
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
@@ -71,6 +72,10 @@ jobs:
7172
# Bust the cache at least once a month - output format: YYYY-MM.
7273
custom-cache-suffix: $(date -u "+%Y-%m")
7374

75+
- name: "Composer: set PHPCS version for tests (lowest)"
76+
if: ${{ matrix.phpcs_version == 'lowest' }}
77+
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction
78+
7479
- name: Lint against parse errors
7580
if: matrix.phpcs_version == 'dev-master'
7681
run: composer lint-lt72

.github/workflows/test.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
if: ${{ matrix.php >= 8.3 }}
6161
uses: "ramsey/composer-install@v2"
6262
with:
63-
composer-options: --ignore-platform-reqs
63+
composer-options: --ignore-platform-req=php+
6464
custom-cache-suffix: $(date -u "+%Y-%m")
6565

6666
- name: "Lint against parse errors (PHP < 7.2)"
@@ -92,13 +92,13 @@ jobs:
9292
#
9393
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
9494
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
95-
phpcs_version: ['3.7.1', 'dev-master']
95+
phpcs_version: ['lowest', 'dev-master']
9696
risky: [false]
9797
experimental: [false]
9898

9999
include:
100100
- php: '5.6'
101-
phpcs_version: '3.7.1'
101+
phpcs_version: 'lowest'
102102
risky: false
103103
experimental: false
104104
extensions: ':iconv' # Run with iconv disabled.
@@ -126,7 +126,7 @@ jobs:
126126
experimental: true
127127

128128
- php: '5.4'
129-
phpcs_version: '3.7.1'
129+
phpcs_version: 'lowest'
130130
risky: true
131131
experimental: true
132132

@@ -136,7 +136,7 @@ jobs:
136136
experimental: true
137137

138138
- php: '8.2'
139-
phpcs_version: '3.7.1'
139+
phpcs_version: 'lowest'
140140
risky: true
141141
experimental: true
142142

@@ -172,8 +172,9 @@ jobs:
172172
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
173173
coverage: none
174174

175-
- name: 'Composer: set PHPCS version for tests'
176-
run: composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}"
175+
- name: "Composer: set PHPCS version for tests (master)"
176+
if: ${{ matrix.phpcs_version != 'lowest' }}
177+
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
177178

178179
# Remove PHPCSDevCS as it would (for now) prevent the tests from being able to run against PHPCS 4.x.
179180
- name: 'Composer: remove PHPCSDevCS'
@@ -193,9 +194,13 @@ jobs:
193194
if: ${{ matrix.php >= 8.3 }}
194195
uses: "ramsey/composer-install@v2"
195196
with:
196-
composer-options: --ignore-platform-reqs
197+
composer-options: --ignore-platform-req=php+
197198
custom-cache-suffix: $(date -u "+%Y-%m")
198199

200+
- name: "Composer: set PHPCS version for tests (lowest)"
201+
if: ${{ matrix.phpcs_version == 'lowest' }}
202+
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction
203+
199204
- name: Run the unit tests without caching (non-risky)
200205
if: ${{ matrix.risky == false }}
201206
run: vendor/bin/phpunit --no-coverage
@@ -246,12 +251,12 @@ jobs:
246251
- php: '8.2'
247252
phpcs_version: 'dev-master'
248253
- php: '8.2'
249-
phpcs_version: '3.7.1'
254+
phpcs_version: 'lowest'
250255
extensions: ':iconv' # Run one build with iconv disabled.
251256
- php: '5.4'
252257
phpcs_version: 'dev-master'
253258
- php: '5.4'
254-
phpcs_version: '3.7.1'
259+
phpcs_version: 'lowest'
255260

256261
name: "Coverage: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
257262

@@ -281,17 +286,20 @@ jobs:
281286
- name: "DEBUG: Show version details"
282287
run: php -v
283288

284-
- name: 'Composer: adjust dependencies'
285-
run: |
286-
# Set a specific PHPCS version.
287-
composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts
289+
- name: "Composer: set PHPCS version for tests (master)"
290+
if: ${{ matrix.phpcs_version != 'lowest' }}
291+
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
288292

289293
- name: Install Composer dependencies
290294
uses: "ramsey/composer-install@v2"
291295
with:
292296
# Bust the cache at least once a month - output format: YYYY-MM.
293297
custom-cache-suffix: $(date -u "+%Y-%m")
294298

299+
- name: "Composer: set PHPCS version for tests (lowest)"
300+
if: ${{ matrix.phpcs_version == 'lowest' }}
301+
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction
302+
295303
- name: Grab PHPUnit version
296304
id: phpunit_version
297305
# yamllint disable-line rule:line-length
@@ -331,17 +339,18 @@ jobs:
331339
php-version: 7.4
332340
coverage: none
333341

342+
# Global install is used to prevent a conflict with the local composer.lock in PHP 8.0+.
334343
- name: Install Coveralls
335344
if: ${{ success() }}
336-
run: composer require php-coveralls/php-coveralls:"^2.4.2"
345+
run: composer global require php-coveralls/php-coveralls:"^2.5.3" --no-interaction
337346

338347
- name: Upload coverage results to Coveralls
339348
if: ${{ success() }}
340349
env:
341350
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
342351
COVERALLS_PARALLEL: true
343352
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
344-
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml
353+
run: php-coveralls -v -x build/logs/clover.xml
345354

346355
coveralls-finish:
347356
needs: coverage
@@ -351,7 +360,7 @@ jobs:
351360

352361
steps:
353362
- name: Coveralls Finished
354-
uses: coverallsapp/github-action@master
363+
uses: coverallsapp/github-action@v2
355364
with:
356365
github-token: ${{ secrets.GITHUB_TOKEN }}
357366
parallel-finished: true

.github/workflows/update-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
retention-days: 5
121121

122122
- name: Setup GH Pages
123-
uses: actions/configure-pages@v2
123+
uses: actions/configure-pages@v3
124124

125125
- name: Build the GH Pages site with Jekyll
126126
uses: actions/jekyll-build-pages@v1
@@ -153,4 +153,4 @@ jobs:
153153
steps:
154154
- name: Deploy to GitHub Pages
155155
id: deployment
156-
uses: actions/deploy-pages@v1
156+
uses: actions/deploy-pages@v2

.github/workflows/update-phpcs-versionnr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
ref: ${{ steps.branches.outputs.BASE }}
5858

5959
- name: Update the version constant in the test file
60-
uses: jacobtomlinson/gha-find-replace@v2
60+
uses: jacobtomlinson/gha-find-replace@v3
6161
with:
6262
find: "const DEVMASTER = '[^']+';"
6363
replace: "const DEVMASTER = '${{ steps.version.outputs.TAG }}';"

CHANGELOG.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use
99

1010
_Nothing yet._
1111

12+
## [1.0.2] - 2023-03-28
13+
14+
### Changed
15+
16+
#### Tokens
17+
18+
* The `Collections::arrayOpenTokensBC()`, `Collections::arrayTokensBC()`, `Collections::listOpenTokensBC()`, `Collections::listTokensBC()`, `Collections::shortArrayListOpenTokensBC()`, `Collections::shortArrayTokensBC()` and `Collections::shortListTokensBC()` token arrays will no longer contain the `T_OPEN_SQUARE_BRACKET` and/or the `T_CLOSE_SQUARE_BRACKET` token constants if PHP_CodeSniffer 3.7.2 or higher is used. [#444]
19+
An upstream bugfix makes it unnecessary to check those tokens for being a short array or short list.
20+
Sniff which use these token arrays is combination with using the `Arrays`/`Lists` classes, should experience a performance boost on PHPCS 3.7.2+ due to this change.
21+
22+
#### Other
23+
24+
* Minor documentation improvements.
25+
* Various small housekeeping and maintenance updates.
26+
27+
### Fixed
28+
29+
#### Utils
30+
31+
* The `Lists::isShortList()` method will now correctly recognize a short list nested in a long list as a short list. [#446]
32+
Note: this is a parse error in PHP, but the method should still handle this correctly.
33+
34+
[#444]: https://github.com/PHPCSStandards/PHPCSUtils/pull/444
35+
[#446]: https://github.com/PHPCSStandards/PHPCSUtils/pull/446
36+
37+
1238
## [1.0.1] - 2023-01-05
1339

1440
### Changed
@@ -18,7 +44,7 @@ _Nothing yet._
1844
* Composer: The version requirements for the [Composer PHPCS plugin] have been widened to allow for version 1.0.0. [#428]
1945
Please ensure you run `composer update phpcsstandards/phpcsutils --with-dependencies` to benefit from this.
2046
* Removed the references to pre-1.0.0 QA releases from the docs. [#425]
21-
* Various small housekeeping and maintainance updates. Thanks [@szepeviktor] for contributing.
47+
* Various small housekeeping and maintenance updates. Thanks [@szepeviktor] for contributing.
2248

2349
[#425]: https://github.com/PHPCSStandards/PHPCSUtils/pull/425
2450
[#428]: https://github.com/PHPCSStandards/PHPCSUtils/pull/428
@@ -58,7 +84,7 @@ For the full list of features, please see the changelogs of the alpha/rc release
5884

5985
#### Other
6086

61-
* Various housekeeping and CI maintainance.
87+
* Various housekeeping and CI maintenance.
6288

6389
### Removed
6490

@@ -259,7 +285,7 @@ Please report any bugs/oversights you encounter!
259285
* Composer: The package will now identify itself as a static analysis tool. Thanks [@GaryJones]! [#341]
260286
* Readme/website homepage: the installation instructions have been updated to include information on installing this library and the included [Composer PHPCS plugin] in combination with Composer >= 2.2. [#291], [#292]
261287
* Various documentation improvements. [#216], [#309], [#394], [#395], [#396], [#398]
262-
* Various housekeeping and CI maintainance.
288+
* Various housekeeping and CI maintenance.
263289
Amongst other things, CI is now run via GitHub Actions ([#239]), the PHPCSUtils native tests now use the [PHPUnit Polyfills] package ([#277]) and the tests are now run against PHP 5.4 - 8.2.
264290

265291
### Deprecated
@@ -779,6 +805,7 @@ This initial alpha release contains the following utility classes:
779805

780806

781807
[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
808+
[1.0.2]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.1...1.0.2
782809
[1.0.1]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0...1.0.1
783810
[1.0.0]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-rc1...1.0.0
784811
[1.0.0-rc1]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-alpha4...1.0.0-rc1

PHPCSUtils/Internal/IsShortArrayOrList.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPCSUtils\BackCompat\Helper;
1717
use PHPCSUtils\Internal\Cache;
1818
use PHPCSUtils\Internal\IsShortArrayOrListWithCache;
19+
use PHPCSUtils\Internal\StableCollections;
1920
use PHPCSUtils\Tokens\Collections;
2021
use PHPCSUtils\Utils\Arrays;
2122
use PHPCSUtils\Utils\Context;
@@ -187,7 +188,7 @@ final class IsShortArrayOrList
187188
public function __construct(File $phpcsFile, $stackPtr)
188189
{
189190
$tokens = $phpcsFile->getTokens();
190-
$openBrackets = Collections::shortArrayListOpenTokensBC();
191+
$openBrackets = StableCollections::$shortArrayListOpenTokensBC;
191192

192193
if (isset($tokens[$stackPtr]) === false
193194
|| isset($openBrackets[$tokens[$stackPtr]['code']]) === false
@@ -471,7 +472,7 @@ private function walkInside($opener, $recursions = 0)
471472
* If we encounter a completely empty item, this must be a short list as arrays cannot contain
472473
* empty items.
473474
*/
474-
if ($item['raw'] === '') {
475+
if ($item['clean'] === '') {
475476
return self::SHORT_LIST;
476477
}
477478

@@ -612,6 +613,12 @@ private function walkOutside()
612613
if ($i === $this->tokens[$i]['parenthesis_opener']
613614
&& $this->tokens[$i]['parenthesis_closer'] > $this->closer
614615
) {
616+
$beforeParensOpen = $this->phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
617+
if ($this->tokens[$beforeParensOpen]['code'] === \T_LIST) {
618+
// Parse error, mixing long and short list, but that's not our concern.
619+
return self::SHORT_LIST;
620+
}
621+
615622
// Found parentheses wrapping this set of brackets before finding a outer set of brackets.
616623
// This will be a short array.
617624
return self::SHORT_ARRAY;

PHPCSUtils/Internal/IsShortArrayOrListWithCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use PHP_CodeSniffer\Files\File;
1414
use PHPCSUtils\Internal\Cache;
1515
use PHPCSUtils\Internal\IsShortArrayOrList;
16-
use PHPCSUtils\Tokens\Collections;
16+
use PHPCSUtils\Internal\StableCollections;
1717

1818
/**
1919
* Determination of short array vs short list vs square brackets.
@@ -215,7 +215,7 @@ private function process()
215215
private function isValidStackPtr()
216216
{
217217
return (isset($this->tokens[$this->stackPtr]) === true
218-
&& isset(Collections::shortArrayTokensBC()[$this->tokens[$this->stackPtr]['code']]) === true);
218+
&& isset(StableCollections::$shortArrayListTokensBC[$this->tokens[$this->stackPtr]['code']]) === true);
219219
}
220220

221221
/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSUtils
6+
* @copyright 2019-2020 PHPCSUtils Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSUtils
9+
*/
10+
11+
namespace PHPCSUtils\Internal;
12+
13+
/**
14+
* Stable collections of related tokens.
15+
*
16+
* The {@see \PHPCSUtils\Tokens\Collections} class contains a range of token collections for use by sniffs,
17+
* some of which may change depending on the availability of a token in PHP/PHPCS.
18+
* The contents of token collections may also vary based on the PHPCS version to allow for optimized sniffing.
19+
*
20+
* The functionality _within_ PHPCSUtils, however, should be stable and reliably testable, so for internal
21+
* use, the most volatile token arrays are replicated here in stable versions to be used by the PHPCSUtils
22+
* functions (and tests) internally.
23+
*
24+
* ---------------------------------------------------------------------------------------------
25+
* This class is only intended for internal use by PHPCSUtils and is not part of the public API.
26+
* This also means that it has no promise of backward compatibility.
27+
*
28+
* End-users should use the methods in the {@see \PHPCSUtils\Tokens\Collections} class instead.
29+
* ---------------------------------------------------------------------------------------------
30+
*
31+
* @internal
32+
*
33+
* @since 1.0.0
34+
*/
35+
final class StableCollections
36+
{
37+
38+
/**
39+
* Tokens which can open a short array or short list (PHPCS cross-version compatible).
40+
*
41+
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` token to allow for handling
42+
* intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
43+
*
44+
* @internal
45+
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
46+
*
47+
* @since 1.0.2
48+
*
49+
* @var array <int|string> => <int|string>
50+
*/
51+
public static $shortArrayListOpenTokensBC = [
52+
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
53+
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
54+
];
55+
56+
/**
57+
* Tokens which are used for short lists.
58+
*
59+
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` and `T_CLOSE_SQUARE_BRACKET` tokens
60+
* to allow for handling intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
61+
*
62+
* @internal
63+
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
64+
*
65+
* @since 1.0.2
66+
*
67+
* @var array <int|string> => <int|string>
68+
*/
69+
public static $shortArrayListTokensBC = [
70+
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
71+
\T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY,
72+
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
73+
\T_CLOSE_SQUARE_BRACKET => \T_CLOSE_SQUARE_BRACKET,
74+
];
75+
}

0 commit comments

Comments
 (0)