Skip to content

Commit 69465ca

Browse files
authored
Merge pull request #496 from PHPCSStandards/develop
Release 1.0.8
2 parents 886a728 + f11e246 commit 69465ca

File tree

13 files changed

+269
-39
lines changed

13 files changed

+269
-39
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ updates:
88
- package-ecosystem: "composer"
99
directory: "/"
1010
schedule:
11-
interval: "daily"
11+
interval: "weekly"
1212
open-pull-requests-limit: 5 # Set to 0 to (temporarily) disable.
1313
versioning-strategy: widen
1414
commit-message:
@@ -20,7 +20,7 @@ updates:
2020
- package-ecosystem: "github-actions"
2121
directory: "/"
2222
schedule:
23-
interval: "daily"
23+
interval: "weekly"
2424
open-pull-requests-limit: 5
2525
commit-message:
2626
prefix: "GH Actions:"

.github/workflows/test.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,37 +349,58 @@ jobs:
349349
PHPCS_VERSION: ${{ matrix.phpcs_version }}
350350
PHPCSUTILS_USE_CACHE: false
351351

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

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

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

373+
# Dependabot does not have access to secrets, other than the GH token.
374+
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
375+
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
376+
- name: Upload coverage results to Coveralls (Dependabot)
377+
if: ${{ success() && github.actor == 'dependabot[bot]' }}
378+
env:
379+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
380+
COVERALLS_PARALLEL: true
381+
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
382+
run: php-coveralls -v -x build/logs/clover.xml
383+
374384
coveralls-finish:
375385
needs: coverage
376386
if: always() && needs.coverage.result == 'success'
377387

378388
runs-on: ubuntu-latest
379389

380390
steps:
381-
- name: Coveralls Finished
391+
- name: Coveralls Finished (normal)
392+
if: ${{ github.actor != 'dependabot[bot]' }}
382393
uses: coverallsapp/github-action@v2
383394
with:
384395
github-token: ${{ secrets.COVERALLS_TOKEN }}
385396
parallel-finished: true
397+
398+
# Dependabot does not have access to secrets, other than the GH token.
399+
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
400+
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
401+
- name: Coveralls Finished (Dependabot)
402+
if: ${{ github.actor == 'dependabot[bot]' }}
403+
uses: coverallsapp/github-action@v2
404+
with:
405+
github-token: ${{ secrets.GITHUB_TOKEN }}
406+
parallel-finished: true

.github/workflows/update-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
destination: ./docs/_site
130130

131131
- name: Upload GH Pages artifact
132-
uses: actions/upload-pages-artifact@v1
132+
uses: actions/upload-pages-artifact@v2
133133
with:
134134
path: ./docs/_site
135135

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ This projects adheres to [Keep a CHANGELOG](https://keepachangelog.com/) and use
1010
_Nothing yet._
1111

1212

13+
## [1.0.8] - 2023-07-17
14+
15+
### Changed
16+
17+
#### PHPCS BackCompat
18+
19+
* `BCFile::getDeclarationName()`: sync with PHPCS 3.8.0 - support for functions called `self`, `parent` or `static` which return by reference. [#494]
20+
21+
#### Other
22+
23+
* Various housekeeping and minor documentation improvements.
24+
25+
### Fixed
26+
27+
#### Fixers
28+
29+
* 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]
30+
31+
[#493]: https://github.com/PHPCSStandards/PHPCSUtils/pull/493
32+
[#494]: https://github.com/PHPCSStandards/PHPCSUtils/pull/494
33+
34+
1335
## [1.0.7] - 2023-07-10
1436

1537
### Changed
@@ -22,7 +44,7 @@ _Nothing yet._
2244

2345
#### Utils
2446

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

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

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

907929

908930
[Unreleased]: https://github.com/PHPCSStandards/PHPCSUtils/compare/stable...HEAD
931+
[1.0.8]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.7...1.0.8
909932
[1.0.7]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.6...1.0.7
910933
[1.0.6]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.5...1.0.6
911934
[1.0.5]: https://github.com/PHPCSStandards/PHPCSUtils/compare/1.0.4...1.0.5

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
*
4949
* Additionally, this class works round the following tokenizer issues for
5050
* any affected utility functions:
51-
* - None at this time.
51+
* - `readonly` classes.
52+
* - Constructor property promotion with `readonly` without visibility.
53+
* - OO methods called `self`, `parent` or `static`.
5254
*
5355
* Most functions in this class will have a related twin-function in the relevant
5456
* class in the `PHPCSUtils\Utils` namespace.
@@ -74,7 +76,7 @@ final class BCFile
7476
*
7577
* Changelog for the PHPCS native function:
7678
* - Introduced in PHPCS 0.0.5.
77-
* - The upstream method has received no significant updates since PHPCS 3.7.1.
79+
* - PHPCS 3.8.0: OO methods called `self`, `parent` or `static` are now correctly recognized.
7880
*
7981
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
8082
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
@@ -96,7 +98,44 @@ final class BCFile
9698
*/
9799
public static function getDeclarationName(File $phpcsFile, $stackPtr)
98100
{
99-
return $phpcsFile->getDeclarationName($stackPtr);
101+
$tokens = $phpcsFile->getTokens();
102+
$tokenCode = $tokens[$stackPtr]['code'];
103+
104+
if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
105+
return null;
106+
}
107+
108+
if ($tokenCode !== T_FUNCTION
109+
&& $tokenCode !== T_CLASS
110+
&& $tokenCode !== T_INTERFACE
111+
&& $tokenCode !== T_TRAIT
112+
&& $tokenCode !== T_ENUM
113+
) {
114+
throw new RuntimeException('Token type "' . $tokens[$stackPtr]['type'] . '" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
115+
}
116+
117+
if ($tokenCode === T_FUNCTION
118+
&& strtolower($tokens[$stackPtr]['content']) !== 'function'
119+
) {
120+
// This is a function declared without the "function" keyword.
121+
// So this token is the function name.
122+
return $tokens[$stackPtr]['content'];
123+
}
124+
125+
$content = null;
126+
for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
127+
if ($tokens[$i]['code'] === T_STRING
128+
// BC: PHPCS < 3.8.0.
129+
|| $tokens[$i]['code'] === T_SELF
130+
|| $tokens[$i]['code'] === T_PARENT
131+
|| $tokens[$i]['code'] === T_STATIC
132+
) {
133+
$content = $tokens[$i]['content'];
134+
break;
135+
}
136+
}
137+
138+
return $content;
100139
}
101140

102141
/**

PHPCSUtils/Fixers/SpacesFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static function checkAndFix(
133133
}
134134

135135
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($ptrA + 1), null, true);
136-
if ($nextNonEmpty < $ptrB) {
136+
if ($nextNonEmpty !== false && $nextNonEmpty < $ptrB) {
137137
throw new RuntimeException(
138138
'The $stackPtr and the $secondPtr token must be adjacent tokens separated only'
139139
. ' by whitespace and/or comments'

Tests/BackCompat/BCFile/GetDeclarationNameTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ enum Suit: int implements Colorful, CardGame {}
8888
/* testFunctionReturnByRefWithReservedKeywordEach */
8989
function &each() {}
9090

91+
/* testFunctionReturnByRefWithReservedKeywordParent */
92+
function &parent() {}
93+
94+
/* testFunctionReturnByRefWithReservedKeywordSelf */
95+
function &self() {}
96+
97+
/* testFunctionReturnByRefWithReservedKeywordStatic */
98+
function &static() {}
99+
91100
/* testLiveCoding */
92101
// Intentional parse error. This has to be the last test in the file.
93102
function // Comment.

Tests/BackCompat/BCFile/GetDeclarationNameTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ public static function dataGetDeclarationName()
196196
'/* testFunctionReturnByRefWithReservedKeywordEach */',
197197
'each',
198198
],
199+
'function-return-by-reference-with-reserved-keyword-parent' => [
200+
'/* testFunctionReturnByRefWithReservedKeywordParent */',
201+
'parent',
202+
],
203+
'function-return-by-reference-with-reserved-keyword-self' => [
204+
'/* testFunctionReturnByRefWithReservedKeywordSelf */',
205+
'self',
206+
],
207+
'function-return-by-reference-with-reserved-keyword-static' => [
208+
'/* testFunctionReturnByRefWithReservedKeywordStatic */',
209+
'static',
210+
],
199211
];
200212
}
201213
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
/* testCommentAtEndOfFile */
4+
echo $foo; // Comment.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
/* testCommentAtEndOfFile */
4+
echo $foo; // Comment.

0 commit comments

Comments
 (0)