Skip to content

Commit

Permalink
Merge pull request #448 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release 1.0.2
  • Loading branch information
jrfnl committed Mar 28, 2023
2 parents 4fd2e30 + f1ddb82 commit e74812a
Show file tree
Hide file tree
Showing 40 changed files with 800 additions and 194 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/quicktest.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
php: ['5.4', 'latest']
phpcs_version: ['3.7.1', 'dev-master']
phpcs_version: ['lowest', 'dev-master']

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

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

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

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

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction

- name: Lint against parse errors
if: matrix.phpcs_version == 'dev-master'
run: composer lint-lt72
Expand Down
43 changes: 26 additions & 17 deletions .github/workflows/test.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
if: ${{ matrix.php >= 8.3 }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-reqs
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

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

include:
- php: '5.6'
phpcs_version: '3.7.1'
phpcs_version: 'lowest'
risky: false
experimental: false
extensions: ':iconv' # Run with iconv disabled.
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
experimental: true

- php: '5.4'
phpcs_version: '3.7.1'
phpcs_version: 'lowest'
risky: true
experimental: true

Expand All @@ -136,7 +136,7 @@ jobs:
experimental: true

- php: '8.2'
phpcs_version: '3.7.1'
phpcs_version: 'lowest'
risky: true
experimental: true

Expand Down Expand Up @@ -172,8 +172,9 @@ jobs:
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none

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

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

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction

- name: Run the unit tests without caching (non-risky)
if: ${{ matrix.risky == false }}
run: vendor/bin/phpunit --no-coverage
Expand Down Expand Up @@ -246,12 +251,12 @@ jobs:
- php: '8.2'
phpcs_version: 'dev-master'
- php: '8.2'
phpcs_version: '3.7.1'
phpcs_version: 'lowest'
extensions: ':iconv' # Run one build with iconv disabled.
- php: '5.4'
phpcs_version: 'dev-master'
- php: '5.4'
phpcs_version: '3.7.1'
phpcs_version: 'lowest'

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

Expand Down Expand Up @@ -281,17 +286,20 @@ jobs:
- name: "DEBUG: Show version details"
run: php -v

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

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

- name: "Composer: set PHPCS version for tests (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction

- name: Grab PHPUnit version
id: phpunit_version
# yamllint disable-line rule:line-length
Expand Down Expand Up @@ -331,17 +339,18 @@ jobs:
php-version: 7.4
coverage: none

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

- name: Upload coverage results to Coveralls
if: ${{ success() }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml
run: php-coveralls -v -x build/logs/clover.xml

coveralls-finish:
needs: coverage
Expand All @@ -351,7 +360,7 @@ jobs:

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
4 changes: 2 additions & 2 deletions .github/workflows/update-docs.yml
Expand Up @@ -120,7 +120,7 @@ jobs:
retention-days: 5

- name: Setup GH Pages
uses: actions/configure-pages@v2
uses: actions/configure-pages@v3

- name: Build the GH Pages site with Jekyll
uses: actions/jekyll-build-pages@v1
Expand Down Expand Up @@ -153,4 +153,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v2
2 changes: 1 addition & 1 deletion .github/workflows/update-phpcs-versionnr.yml
Expand Up @@ -57,7 +57,7 @@ jobs:
ref: ${{ steps.branches.outputs.BASE }}

- name: Update the version constant in the test file
uses: jacobtomlinson/gha-find-replace@v2
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "const DEVMASTER = '[^']+';"
replace: "const DEVMASTER = '${{ steps.version.outputs.TAG }}';"
Expand Down
33 changes: 30 additions & 3 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,32 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use

_Nothing yet._

## [1.0.2] - 2023-03-28

### Changed

#### Tokens

* 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]
An upstream bugfix makes it unnecessary to check those tokens for being a short array or short list.
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.

#### Other

* Minor documentation improvements.
* Various small housekeeping and maintenance updates.

### Fixed

#### Utils

* The `Lists::isShortList()` method will now correctly recognize a short list nested in a long list as a short list. [#446]
Note: this is a parse error in PHP, but the method should still handle this correctly.

[#444]: https://github.com/PHPCSStandards/PHPCSUtils/pull/444
[#446]: https://github.com/PHPCSStandards/PHPCSUtils/pull/446


## [1.0.1] - 2023-01-05

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

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

#### Other

* Various housekeeping and CI maintainance.
* Various housekeeping and CI maintenance.

### Removed

Expand Down Expand Up @@ -259,7 +285,7 @@ Please report any bugs/oversights you encounter!
* Composer: The package will now identify itself as a static analysis tool. Thanks [@GaryJones]! [#341]
* 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]
* Various documentation improvements. [#216], [#309], [#394], [#395], [#396], [#398]
* Various housekeeping and CI maintainance.
* Various housekeeping and CI maintenance.
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.

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


[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
[1.0.2]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-rc1...1.0.0
[1.0.0-rc1]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.0-alpha4...1.0.0-rc1
Expand Down
11 changes: 9 additions & 2 deletions PHPCSUtils/Internal/IsShortArrayOrList.php
Expand Up @@ -16,6 +16,7 @@
use PHPCSUtils\BackCompat\Helper;
use PHPCSUtils\Internal\Cache;
use PHPCSUtils\Internal\IsShortArrayOrListWithCache;
use PHPCSUtils\Internal\StableCollections;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Utils\Arrays;
use PHPCSUtils\Utils\Context;
Expand Down Expand Up @@ -187,7 +188,7 @@ final class IsShortArrayOrList
public function __construct(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$openBrackets = Collections::shortArrayListOpenTokensBC();
$openBrackets = StableCollections::$shortArrayListOpenTokensBC;

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

Expand Down Expand Up @@ -612,6 +613,12 @@ private function walkOutside()
if ($i === $this->tokens[$i]['parenthesis_opener']
&& $this->tokens[$i]['parenthesis_closer'] > $this->closer
) {
$beforeParensOpen = $this->phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
if ($this->tokens[$beforeParensOpen]['code'] === \T_LIST) {
// Parse error, mixing long and short list, but that's not our concern.
return self::SHORT_LIST;
}

// Found parentheses wrapping this set of brackets before finding a outer set of brackets.
// This will be a short array.
return self::SHORT_ARRAY;
Expand Down
4 changes: 2 additions & 2 deletions PHPCSUtils/Internal/IsShortArrayOrListWithCache.php
Expand Up @@ -13,7 +13,7 @@
use PHP_CodeSniffer\Files\File;
use PHPCSUtils\Internal\Cache;
use PHPCSUtils\Internal\IsShortArrayOrList;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Internal\StableCollections;

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

/**
Expand Down
75 changes: 75 additions & 0 deletions PHPCSUtils/Internal/StableCollections.php
@@ -0,0 +1,75 @@
<?php
/**
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019-2020 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/

namespace PHPCSUtils\Internal;

/**
* Stable collections of related tokens.
*
* The {@see \PHPCSUtils\Tokens\Collections} class contains a range of token collections for use by sniffs,
* some of which may change depending on the availability of a token in PHP/PHPCS.
* The contents of token collections may also vary based on the PHPCS version to allow for optimized sniffing.
*
* The functionality _within_ PHPCSUtils, however, should be stable and reliably testable, so for internal
* use, the most volatile token arrays are replicated here in stable versions to be used by the PHPCSUtils
* functions (and tests) internally.
*
* ---------------------------------------------------------------------------------------------
* This class is only intended for internal use by PHPCSUtils and is not part of the public API.
* This also means that it has no promise of backward compatibility.
*
* End-users should use the methods in the {@see \PHPCSUtils\Tokens\Collections} class instead.
* ---------------------------------------------------------------------------------------------
*
* @internal
*
* @since 1.0.0
*/
final class StableCollections
{

/**
* Tokens which can open a short array or short list (PHPCS cross-version compatible).
*
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` token to allow for handling
* intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
*
* @internal
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
*
* @since 1.0.2
*
* @var array <int|string> => <int|string>
*/
public static $shortArrayListOpenTokensBC = [
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
];

/**
* Tokens which are used for short lists.
*
* This array will ALWAYS include the `T_OPEN_SQUARE_BRACKET` and `T_CLOSE_SQUARE_BRACKET` tokens
* to allow for handling intermittent tokenizer issues related to the retokenization to `T_OPEN_SHORT_ARRAY`.
*
* @internal
* @ignore This array is only for internal use by PHPCSUtils and is not part of the public API.
*
* @since 1.0.2
*
* @var array <int|string> => <int|string>
*/
public static $shortArrayListTokensBC = [
\T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
\T_CLOSE_SHORT_ARRAY => \T_CLOSE_SHORT_ARRAY,
\T_OPEN_SQUARE_BRACKET => \T_OPEN_SQUARE_BRACKET,
\T_CLOSE_SQUARE_BRACKET => \T_CLOSE_SQUARE_BRACKET,
];
}

0 comments on commit e74812a

Please sign in to comment.