Skip to content

Commit 7029c05

Browse files
authored
Merge pull request #221 from PHPCSStandards/develop
Release PHPCSExtra 1.0.3
2 parents a077c4a + cdf5de5 commit 7029c05

17 files changed

+198
-37
lines changed

.github/workflows/quicktest.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
matrix:
3131
php: ['5.4', 'latest']
32-
phpcs_version: ['3.7.1', 'dev-master']
32+
phpcs_version: ['lowest', 'dev-master']
3333

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

@@ -55,8 +55,9 @@ jobs:
5555
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
5656
coverage: none
5757

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

6162
# Install dependencies and handle caching in one go.
6263
# @link https://github.com/marketplace/actions/install-composer-dependencies
@@ -72,9 +73,13 @@ jobs:
7273
if: matrix.php == 'latest'
7374
uses: "ramsey/composer-install@v2"
7475
with:
75-
composer-options: --ignore-platform-reqs
76+
composer-options: --ignore-platform-req=php+
7677
custom-cache-suffix: $(date -u "+%Y-%m")
7778

79+
- name: "Composer: set PHPCS version for tests (lowest)"
80+
if: ${{ matrix.phpcs_version == 'lowest' }}
81+
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
82+
7883
- name: Lint against parse errors
7984
if: matrix.phpcs_version == 'dev-master'
8085
run: composer lint

.github/workflows/test.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
#
3434
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
3535
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3']
36-
phpcs_version: ['3.7.1', 'dev-master']
36+
phpcs_version: ['lowest', 'dev-master']
3737

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

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

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

6768
# Install dependencies and handle caching in one go.
6869
# @link https://github.com/marketplace/actions/install-composer-dependencies
@@ -78,9 +79,13 @@ jobs:
7879
if: ${{ startsWith( matrix.php, '8' ) }}
7980
uses: "ramsey/composer-install@v2"
8081
with:
81-
composer-options: --ignore-platform-reqs
82+
composer-options: --ignore-platform-req=php+
8283
custom-cache-suffix: $(date -u "+%Y-%m")
8384

85+
- name: "Composer: set PHPCS version for tests (lowest)"
86+
if: ${{ matrix.phpcs_version == 'lowest' }}
87+
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
88+
8489
- name: Lint against parse errors
8590
if: matrix.phpcs_version == 'dev-master'
8691
run: composer lint
@@ -109,7 +114,7 @@ jobs:
109114
matrix:
110115
# 7.4 should be updated to 8.2 when higher PHPUnit versions can be supported.
111116
php: ['5.4', '7.4']
112-
phpcs_version: ['3.7.1', 'dev-master']
117+
phpcs_version: ['lowest', 'dev-master']
113118

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

@@ -136,10 +141,9 @@ jobs:
136141
coverage: xdebug
137142
tools: cs2pr
138143

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

144148
# Install dependencies and handle caching in one go.
145149
# @link https://github.com/marketplace/actions/install-composer-dependencies
@@ -149,6 +153,10 @@ jobs:
149153
# Bust the cache at least once a month - output format: YYYY-MM.
150154
custom-cache-suffix: $(date -u "+%Y-%m")
151155

156+
- name: "Composer: set PHPCS version for tests (lowest)"
157+
if: ${{ matrix.phpcs_version == 'lowest' }}
158+
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
159+
152160
- name: Lint against parse errors
153161
if: matrix.phpcs_version == 'dev-master'
154162
run: composer lint -- --checkstyle | cs2pr
@@ -164,17 +172,18 @@ jobs:
164172
php-version: 7.4
165173
coverage: none
166174

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

171180
- name: Upload coverage results to Coveralls
172181
if: ${{ success() }}
173182
env:
174183
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
175184
COVERALLS_PARALLEL: true
176185
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
177-
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml
186+
run: php-coveralls -v -x build/logs/clover.xml
178187

179188
coveralls-finish:
180189
needs: coverage
@@ -184,7 +193,7 @@ jobs:
184193

185194
steps:
186195
- name: Coveralls Finished
187-
uses: coverallsapp/github-action@master
196+
uses: coverallsapp/github-action@v2
188197
with:
189198
github-token: ${{ secrets.GITHUB_TOKEN }}
190199
parallel-finished: true

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses
1414

1515
_Nothing yet._
1616

17+
## [1.0.3] - 2023-03-28
18+
19+
### Changed
20+
21+
#### Universal
22+
23+
* `Universal.WhiteSpace.DisallowInlineTabs`: significant performance improvement. [#216], [#217]
24+
25+
#### Other
26+
27+
* Various housekeeping.
28+
29+
### Fixed
30+
31+
#### Modernize
32+
33+
* `Modernize.FunctionCalls.Dirname`: prevent false positives for attribute classes called `dirname`. [#211], [#213]
34+
35+
[#211]: https://github.com/PHPCSStandards/PHPCSExtra/pull/211
36+
[#213]: https://github.com/PHPCSStandards/PHPCSExtra/pull/213
37+
[#216]: https://github.com/PHPCSStandards/PHPCSExtra/pull/216
38+
[#217]: https://github.com/PHPCSStandards/PHPCSExtra/pull/217
39+
40+
1741
## [1.0.2] - 2023-01-10
1842

1943
### Changed
@@ -398,6 +422,7 @@ This initial alpha release contains the following sniffs:
398422
[php_version-config]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-php-version
399423

400424
[Unreleased]: https://github.com/PHPCSStandards/PHPCSExtra/compare/stable...HEAD
425+
[1.0.3]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.2...1.0.3
401426
[1.0.2]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.1...1.0.2
402427
[1.0.1]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0...1.0.1
403428
[1.0.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.0-rc1...1.0.0

Modernize/Sniffs/FunctionCalls/DirnameSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHP_CodeSniffer\Sniffs\Sniff;
1515
use PHP_CodeSniffer\Util\Tokens;
1616
use PHPCSUtils\Tokens\Collections;
17+
use PHPCSUtils\Utils\Context;
1718
use PHPCSUtils\Utils\PassedParameters;
1819

1920
/**
@@ -70,6 +71,11 @@ public function process(File $phpcsFile, $stackPtr)
7071
return;
7172
}
7273

74+
if (Context::inAttribute($phpcsFile, $stackPtr) === true) {
75+
// Class instantiation in attribute, not function call.
76+
return;
77+
}
78+
7379
// Check if it is really a function call to the global function.
7480
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
7581

Modernize/Tests/FunctionCalls/DirnameUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ $path = dirname(
136136
)
137137
);
138138

139+
class AttributesShouldBeIgnored
140+
{
141+
#[DirName(__FILE__)]
142+
public function foo(): void
143+
{}
144+
}
139145

140146
// Parse error.
141147
// This must be the last test in the file.

Modernize/Tests/FunctionCalls/DirnameUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ $path = dirname(
120120
path: __DIR__
121121
, levels: 6);
122122

123+
class AttributesShouldBeIgnored
124+
{
125+
#[DirName(__FILE__)]
126+
public function foo(): void
127+
{}
128+
}
123129

124130
// Parse error.
125131
// This must be the last test in the file.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ If unsure whether the changes you are proposing would be welcome, open an issue
470470

471471
License
472472
-------
473-
This code is released under the GNU Lesser General Public License (LGPLv3). For more information, visit <http://www.gnu.org/copyleft/lesser.html>
473+
This code is released under the [GNU Lesser General Public License (LGPLv3)](LICENSE).
474474

475475

476476
[phpcsextra-packagist]: https://packagist.org/packages/phpcsstandards/phpcsextra

Universal/Sniffs/WhiteSpace/DisallowInlineTabsSniff.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ public function process(File $phpcsFile, $stackPtr)
9494
$this->tabWidth = Helper::getTabWidth($phpcsFile);
9595
}
9696

97+
if (defined('PHP_CODESNIFFER_IN_TESTS')) {
98+
$this->tabWidth = Helper::getCommandLineData($phpcsFile, 'tabWidth');
99+
}
100+
97101
$tokens = $phpcsFile->getTokens();
102+
$dummy = new DummyTokenizer('', $phpcsFile->config);
98103

99104
for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
100105
// Skip all non-whitespace tokens and skip whitespace at the start of a new line.
@@ -109,10 +114,18 @@ public function process(File $phpcsFile, $stackPtr)
109114
// If tabs haven't been converted to spaces by the tokenizer, do so now.
110115
$token = $tokens[$i];
111116
if (isset($token['orig_content']) === false) {
112-
$dummy = new DummyTokenizer('', $phpcsFile->config);
113-
$dummy->replaceTabsInToken($token, ' ', ' ', $this->tabWidth);
117+
if ($token['content'] === '' || \strpos($token['content'], "\t") === false) {
118+
// If there are no tabs, we can continue, no matter what.
119+
continue;
120+
}
121+
122+
$dummy->replaceTabsInToken($token);
114123
}
115124

125+
/*
126+
* Tokens only have the 'orig_content' key if they contain tabs,
127+
* so from here on out, we **know** there will be tabs in the content.
128+
*/
116129
$origContent = $token['orig_content'];
117130

118131
$multiLineComment = false;
@@ -131,8 +144,6 @@ public function process(File $phpcsFile, $stackPtr)
131144
if ($commentOnly === '' || \strpos($commentOnly, "\t") === false) {
132145
continue;
133146
}
134-
} elseif ($origContent === '' || \strpos($origContent, "\t") === false) {
135-
continue;
136147
}
137148

138149
$fix = $phpcsFile->addFixableError(

Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.1.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ $anon = new class // Comment
2626

2727
$b = new class ( /*comment*/ ) {};
2828

29+
/*
30+
* Safeguard handling of anon classes with attributes.
31+
*/
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class() {}; // Bad.
36+
37+
$anon = new
38+
#[MyAttribute, AnotherAttribute]
39+
class {}; // OK.
40+
2941
// Live coding.
3042
// Intentional parse error. This has to be the last test in the file.
3143
$anon = new class()

Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.1.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ $anon = new class // Comment
2626

2727
$b = new class /*comment*/ {};
2828

29+
/*
30+
* Safeguard handling of anon classes with attributes.
31+
*/
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class {}; // Bad.
36+
37+
$anon = new
38+
#[MyAttribute, AnotherAttribute]
39+
class {}; // OK.
40+
2941
// Live coding.
3042
// Intentional parse error. This has to be the last test in the file.
3143
$anon = new class()

0 commit comments

Comments
 (0)