Skip to content

Commit

Permalink
Merge pull request #496 from PHPCSStandards/develop
Browse files Browse the repository at this point in the history
Release 1.0.8
  • Loading branch information
jrfnl committed Jul 16, 2023
2 parents 886a728 + f11e246 commit 69465ca
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Expand Up @@ -8,7 +8,7 @@ updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
open-pull-requests-limit: 5 # Set to 0 to (temporarily) disable.
versioning-strategy: widen
commit-message:
Expand All @@ -20,7 +20,7 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
open-pull-requests-limit: 5
commit-message:
prefix: "GH Actions:"
Expand Down
41 changes: 31 additions & 10 deletions .github/workflows/test.yml
Expand Up @@ -349,37 +349,58 @@ jobs:
PHPCS_VERSION: ${{ matrix.phpcs_version }}
PHPCSUTILS_USE_CACHE: false

# Uploading the results with PHP Coveralls v1 won't work from GH Actions, so switch the PHP version.
# Also PHP Coveralls itself (still) isn't fully compatible with PHP 8.0+.
- name: Switch to PHP 7.4
if: ${{ success() && matrix.php != '7.4' }}
# PHP Coveralls v2 (which supports GH Actions) has a PHP 5.5 minimum, so switch the PHP version.
- name: Switch to PHP latest
if: ${{ success() && matrix.php == '5.4' }}
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 'latest'
coverage: none

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

- name: Upload coverage results to Coveralls
if: ${{ success() }}
- name: Upload coverage results to Coveralls (normal)
if: ${{ success() && github.actor != 'dependabot[bot]' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: php-coveralls -v -x build/logs/clover.xml

# Dependabot does not have access to secrets, other than the GH token.
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
- name: Upload coverage results to Coveralls (Dependabot)
if: ${{ success() && github.actor == 'dependabot[bot]' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
run: php-coveralls -v -x build/logs/clover.xml

coveralls-finish:
needs: coverage
if: always() && needs.coverage.result == 'success'

runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
- name: Coveralls Finished (normal)
if: ${{ github.actor != 'dependabot[bot]' }}
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_TOKEN }}
parallel-finished: true

# Dependabot does not have access to secrets, other than the GH token.
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
- name: Coveralls Finished (Dependabot)
if: ${{ github.actor == 'dependabot[bot]' }}
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
2 changes: 1 addition & 1 deletion .github/workflows/update-docs.yml
Expand Up @@ -129,7 +129,7 @@ jobs:
destination: ./docs/_site

- name: Upload GH Pages artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v2
with:
path: ./docs/_site

Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG.md
Expand Up @@ -10,6 +10,28 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use
_Nothing yet._


## [1.0.8] - 2023-07-17

### Changed

#### PHPCS BackCompat

* `BCFile::getDeclarationName()`: sync with PHPCS 3.8.0 - support for functions called `self`, `parent` or `static` which return by reference. [#494]

#### Other

* Various housekeeping and minor documentation improvements.

### Fixed

#### Fixers

* The [`SpacesFixer`] will no longer throw an (incorrect) exception when the second pointer passed is a comment token and this comment token is the last content in a file. [#493]

[#493]: https://github.com/PHPCSStandards/PHPCSUtils/pull/493
[#494]: https://github.com/PHPCSStandards/PHPCSUtils/pull/494


## [1.0.7] - 2023-07-10

### Changed
Expand All @@ -22,7 +44,7 @@ _Nothing yet._

#### Utils

* The `Arrays::getDoubleArrowPtr()` method could previously get confused over a double arrow in a keyed lists used as an array value. [#485]
* The `Arrays::getDoubleArrowPtr()` method could previously get confused over a double arrow in a keyed list used as an array value. [#485]

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

Expand Down Expand Up @@ -906,6 +928,7 @@ This initial alpha release contains the following utility classes:


[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
[1.0.8]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.7...1.0.8
[1.0.7]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.6...1.0.7
[1.0.6]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.5...1.0.6
[1.0.5]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.4...1.0.5
Expand Down
45 changes: 42 additions & 3 deletions PHPCSUtils/BackCompat/BCFile.php
Expand Up @@ -48,7 +48,9 @@
*
* Additionally, this class works round the following tokenizer issues for
* any affected utility functions:
* - None at this time.
* - `readonly` classes.
* - Constructor property promotion with `readonly` without visibility.
* - OO methods called `self`, `parent` or `static`.
*
* Most functions in this class will have a related twin-function in the relevant
* class in the `PHPCSUtils\Utils` namespace.
Expand All @@ -74,7 +76,7 @@ final class BCFile
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.7.1.
* - PHPCS 3.8.0: OO methods called `self`, `parent` or `static` are now correctly recognized.
*
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
Expand All @@ -96,7 +98,44 @@ final class BCFile
*/
public static function getDeclarationName(File $phpcsFile, $stackPtr)
{
return $phpcsFile->getDeclarationName($stackPtr);
$tokens = $phpcsFile->getTokens();
$tokenCode = $tokens[$stackPtr]['code'];

if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
return null;
}

if ($tokenCode !== T_FUNCTION
&& $tokenCode !== T_CLASS
&& $tokenCode !== T_INTERFACE
&& $tokenCode !== T_TRAIT
&& $tokenCode !== T_ENUM
) {
throw new RuntimeException('Token type "' . $tokens[$stackPtr]['type'] . '" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
}

if ($tokenCode === T_FUNCTION
&& strtolower($tokens[$stackPtr]['content']) !== 'function'
) {
// This is a function declared without the "function" keyword.
// So this token is the function name.
return $tokens[$stackPtr]['content'];
}

$content = null;
for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
if ($tokens[$i]['code'] === T_STRING
// BC: PHPCS < 3.8.0.
|| $tokens[$i]['code'] === T_SELF
|| $tokens[$i]['code'] === T_PARENT
|| $tokens[$i]['code'] === T_STATIC
) {
$content = $tokens[$i]['content'];
break;
}
}

return $content;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Fixers/SpacesFixer.php
Expand Up @@ -133,7 +133,7 @@ public static function checkAndFix(
}

$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($ptrA + 1), null, true);
if ($nextNonEmpty < $ptrB) {
if ($nextNonEmpty !== false && $nextNonEmpty < $ptrB) {
throw new RuntimeException(
'The $stackPtr and the $secondPtr token must be adjacent tokens separated only'
. ' by whitespace and/or comments'
Expand Down
9 changes: 9 additions & 0 deletions Tests/BackCompat/BCFile/GetDeclarationNameTest.inc
Expand Up @@ -88,6 +88,15 @@ enum Suit: int implements Colorful, CardGame {}
/* testFunctionReturnByRefWithReservedKeywordEach */
function &each() {}

/* testFunctionReturnByRefWithReservedKeywordParent */
function &parent() {}

/* testFunctionReturnByRefWithReservedKeywordSelf */
function &self() {}

/* testFunctionReturnByRefWithReservedKeywordStatic */
function &static() {}

/* testLiveCoding */
// Intentional parse error. This has to be the last test in the file.
function // Comment.
12 changes: 12 additions & 0 deletions Tests/BackCompat/BCFile/GetDeclarationNameTest.php
Expand Up @@ -196,6 +196,18 @@ public static function dataGetDeclarationName()
'/* testFunctionReturnByRefWithReservedKeywordEach */',
'each',
],
'function-return-by-reference-with-reserved-keyword-parent' => [
'/* testFunctionReturnByRefWithReservedKeywordParent */',
'parent',
],
'function-return-by-reference-with-reserved-keyword-self' => [
'/* testFunctionReturnByRefWithReservedKeywordSelf */',
'self',
],
'function-return-by-reference-with-reserved-keyword-static' => [
'/* testFunctionReturnByRefWithReservedKeywordStatic */',
'static',
],
];
}
}
4 changes: 4 additions & 0 deletions Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.inc
@@ -0,0 +1,4 @@
<?php

/* testCommentAtEndOfFile */
echo $foo; // Comment.
4 changes: 4 additions & 0 deletions Tests/Fixers/SpacesFixer/SpacesFixerAtEOFTest.inc.fixed
@@ -0,0 +1,4 @@
<?php

/* testCommentAtEndOfFile */
echo $foo; // Comment.

0 comments on commit 69465ca

Please sign in to comment.