Skip to content

Commit 78b2cae

Browse files
authored
Merge pull request #296 from PHPCSStandards/develop
Release PHPCSExtra 1.2.0
2 parents 746c319 + 9f90980 commit 78b2cae

30 files changed

+1563
-101
lines changed

.github/SECURITY.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/basics.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
composer require --no-update squizlabs/php_codesniffer:"dev-master" --no-interaction
4949
5050
# Install dependencies and handle caching in one go.
51-
# @link https://github.com/marketplace/actions/install-composer-dependencies
51+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
5252
- name: Install Composer dependencies
5353
uses: "ramsey/composer-install@v2"
5454
with:
@@ -62,7 +62,8 @@ jobs:
6262
6363
# Show XML violations inline in the file diff.
6464
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
65-
- uses: korelstar/xmllint-problem-matcher@v1
65+
- name: Enable showing XML issues inline
66+
uses: korelstar/xmllint-problem-matcher@v1
6667

6768
# Validate the Ruleset XML file.
6869
# @link http://xmlsoft.org/xmllint.html
@@ -112,7 +113,7 @@ jobs:
112113

113114
# Install dependencies and handle caching in one go.
114115
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
115-
# @link https://github.com/marketplace/actions/install-composer-dependencies
116+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
116117
- name: Install Composer dependencies
117118
uses: "ramsey/composer-install@v2"
118119
with:
@@ -131,7 +132,7 @@ jobs:
131132
uses: actions/checkout@v4
132133

133134
- name: Set up node and enable caching of dependencies
134-
uses: actions/setup-node@v3
135+
uses: actions/setup-node@v4
135136
with:
136137
node-version: '16'
137138

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Remove outdated labels
2+
3+
on:
4+
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
5+
issues:
6+
types:
7+
- closed
8+
pull_request_target:
9+
types:
10+
- closed
11+
12+
jobs:
13+
on-issue-close:
14+
runs-on: ubuntu-latest
15+
if: github.repository_owner == 'PHPCSStandards' && github.event.issue.state == 'closed'
16+
17+
name: Clean up labels on issue close
18+
19+
steps:
20+
- uses: mondeja/remove-labels-gh-action@v1
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
labels: |
24+
Status: awaiting feedback
25+
Status: wait for upstream
26+
27+
on-pr-merge:
28+
runs-on: ubuntu-latest
29+
if: github.repository_owner == 'PHPCSStandards' && github.event.pull_request.merged == true
30+
31+
name: Clean up labels on PR merge
32+
33+
steps:
34+
- uses: mondeja/remove-labels-gh-action@v1
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
labels: |
38+
Status: awaiting feedback
39+
Status: wait for upstream
40+
41+
on-pr-close:
42+
runs-on: ubuntu-latest
43+
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target' && github.event.pull_request.merged == false
44+
45+
name: Clean up labels on PR close
46+
47+
steps:
48+
- uses: mondeja/remove-labels-gh-action@v1
49+
with:
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
labels: |
52+
Status: awaiting feedback
53+
Status: wait for upstream

.github/workflows/quicktest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
6161

6262
# Install dependencies and handle caching in one go.
63-
# @link https://github.com/marketplace/actions/install-composer-dependencies
63+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
6464
- name: Install Composer dependencies - normal
6565
if: matrix.php != 'latest'
6666
uses: "ramsey/composer-install@v2"

.github/workflows/test.yml

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ jobs:
3232
# @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
3333
#
3434
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
35-
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3']
35+
php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3', '8.4']
3636
phpcs_version: ['lowest', 'dev-master']
3737

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

40-
continue-on-error: ${{ matrix.php == '8.3' }}
40+
continue-on-error: ${{ matrix.php == '8.4' }}
4141

4242
steps:
4343
- name: Checkout code
@@ -66,7 +66,7 @@ jobs:
6666
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
6767

6868
# Install dependencies and handle caching in one go.
69-
# @link https://github.com/marketplace/actions/install-composer-dependencies
69+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
7070
- name: Install Composer dependencies - normal
7171
if: ${{ startsWith( matrix.php, '8' ) == false }}
7272
uses: "ramsey/composer-install@v2"
@@ -148,7 +148,7 @@ jobs:
148148
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
149149

150150
# Install dependencies and handle caching in one go.
151-
# @link https://github.com/marketplace/actions/install-composer-dependencies
151+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
152152
- name: Install Composer dependencies
153153
uses: "ramsey/composer-install@v2"
154154
with:
@@ -168,37 +168,14 @@ jobs:
168168
- name: Run the unit tests with code coverage
169169
run: composer coverage
170170

171-
# PHP Coveralls v2 (which supports GH Actions) has a PHP 5.5 minimum, so switch the PHP version.
172-
- name: Switch to PHP latest
173-
if: ${{ success() && matrix.php == '5.4' }}
174-
uses: shivammathur/setup-php@v2
175-
with:
176-
php-version: 'latest'
177-
coverage: none
178-
179-
# Global install is used to prevent a conflict with the local composer.lock.
180-
- name: Install Coveralls
171+
- name: Upload coverage results to Coveralls
181172
if: ${{ success() }}
182-
run: composer global require php-coveralls/php-coveralls:"^2.6.0" --no-interaction
183-
184-
- name: Upload coverage results to Coveralls (normal)
185-
if: ${{ success() && github.actor != 'dependabot[bot]' }}
186-
env:
187-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
188-
COVERALLS_PARALLEL: true
189-
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
190-
run: php-coveralls -v -x build/logs/clover.xml
191-
192-
# Dependabot does not have access to secrets, other than the GH token.
193-
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
194-
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
195-
- name: Upload coverage results to Coveralls (Dependabot)
196-
if: ${{ success() && github.actor == 'dependabot[bot]' }}
197-
env:
198-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
199-
COVERALLS_PARALLEL: true
200-
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
201-
run: php-coveralls -v -x build/logs/clover.xml
173+
uses: coverallsapp/github-action@v2
174+
with:
175+
format: clover
176+
file: build/logs/clover.xml
177+
flag-name: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
178+
parallel: true
202179

203180
coveralls-finish:
204181
needs: coverage
@@ -207,19 +184,7 @@ jobs:
207184
runs-on: ubuntu-latest
208185

209186
steps:
210-
- name: Coveralls Finished (normal)
211-
if: ${{ github.actor != 'dependabot[bot]' }}
212-
uses: coverallsapp/github-action@v2
213-
with:
214-
github-token: ${{ secrets.COVERALLS_TOKEN }}
215-
parallel-finished: true
216-
217-
# Dependabot does not have access to secrets, other than the GH token.
218-
# Ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions
219-
# Ref: https://github.com/lemurheavy/coveralls-public/issues/1721
220-
- name: Coveralls Finished (Dependabot)
221-
if: ${{ github.actor == 'dependabot[bot]' }}
187+
- name: Coveralls Finished
222188
uses: coverallsapp/github-action@v2
223189
with:
224-
github-token: ${{ secrets.GITHUB_TOKEN }}
225190
parallel-finished: true

.yamllint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ yaml-files:
66
- '*.yaml'
77
- '*.yml'
88
- '.yamllint'
9+
- 'phpstan.neon*'
910

1011
# Rule documentation: https://yamllint.readthedocs.io/en/stable/rules.html
1112
rules:

CHANGELOG.md

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

1515
_Nothing yet._
1616

17+
## [1.2.0] - 2023-12-02
18+
19+
### Added
20+
21+
#### Universal
22+
23+
* :wrench: :books: New `Universal.CodeAnalysis.NoDoubleNegative` sniff to detect double negatives (!!) and advise to use a boolean cast instead. Thanks [@diedexx] for reviewing. [#277]
24+
* :wrench: :books: New `Universal.Operators.ConcatPosition` sniff to enforce that the concatenation operator for multi-line concatenations is in a preferred position, either always at the start of the next line or always at the end of the previous line. [#294]
25+
* :wrench: :bar_chart: :books: New `Universal.PHP.LowercasePHPTag` sniff to enforce that the "PHP" in a PHP open tag is lowercase. Thanks [@fredden] for reviewing. [#276]
26+
27+
### Changed
28+
29+
#### NormalizedArrays
30+
31+
* `NormalizedArrays.Arrays.CommaAfterLast`: the sniff now has two extra error codes to distinguish between multi-line arrays with the last array item on the _same line_ as the array closer vs the last array item being on a line _before_ the array closer. Thanks [@stronk7] for suggesting and patching this. [#283], [#284]
32+
These new error codes allow for selectively excluding that specific situation from triggering the sniff.
33+
The new error codes are `FoundMultiLineCloserSameLine` (for `multiLine="forbid"`) and `MissingMultiLineCloserSameLine` (for `multiLine="enforce"`).
34+
The pre-existing `FoundMultiLine` and `FoundSingleLine` error codes continue to be used for multi-line arrays with the last array item on a different line than the array closer.
35+
36+
#### Other
37+
38+
* Various housekeeping.
39+
40+
[#276]: https://github.com/PHPCSStandards/PHPCSExtra/pull/276
41+
[#277]: https://github.com/PHPCSStandards/PHPCSExtra/pull/277
42+
[#283]: https://github.com/PHPCSStandards/PHPCSExtra/issues/283
43+
[#284]: https://github.com/PHPCSStandards/PHPCSExtra/pull/284
44+
[#294]: https://github.com/PHPCSStandards/PHPCSExtra/pull/294
45+
46+
1747
## [1.1.2] - 2023-09-21
1848

1949
### Changed
@@ -523,6 +553,7 @@ This initial alpha release contains the following sniffs:
523553
[php_version-config]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-php-version
524554

525555
[Unreleased]: https://github.com/PHPCSStandards/PHPCSExtra/compare/stable...HEAD
556+
[1.2.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.2...1.2.0
526557
[1.1.2]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.1...1.1.2
527558
[1.1.1]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.1.0...1.1.1
528559
[1.1.0]: https://github.com/PHPCSStandards/PHPCSExtra/compare/1.0.4...1.1.0
@@ -537,5 +568,8 @@ This initial alpha release contains the following sniffs:
537568

538569
[@anomiex]: https://github.com/anomiex
539570
[@derickr]: https://github.com/derickr
571+
[@diedexx]: https://github.com/diedexx
572+
[@fredden]: https://github.com/fredden
540573
[@GaryJones]: https://github.com/GaryJones
574+
[@stronk7]: https://github.com/stronk7
541575
[@szepeviktor]: https://github.com/szepeviktor

NormalizedArrays/Sniffs/Arrays/CommaAfterLastSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public function process(File $phpcsFile, $stackPtr)
145145
return;
146146
}
147147

148+
// If the closer is on the same line as the last element, change the error code for multi-line arrays.
149+
if ($errorCode === 'MultiLine'
150+
&& $tokens[$lastNonEmpty]['line'] === $tokens[$closer]['line']
151+
) {
152+
$errorCode .= 'CloserSameLine';
153+
}
154+
148155
$isComma = ($tokens[$lastNonEmpty]['code'] === \T_COMMA);
149156

150157
$phpcsFile->recordMetric(

NormalizedArrays/Tests/Arrays/CommaAfterLastUnitTest.1.inc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,56 @@ EOD
166166
, /*comment*/
167167
) );
168168

169+
/**
170+
* Tests enforcing a comma after the last array item when the closer is in the same line. See #283.
171+
*/
172+
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine enforce
173+
174+
$missing = array(
175+
1, 2,
176+
3, 4);
177+
178+
$missing = [
179+
'1', '2',
180+
'3', '4'];
181+
182+
$missing_but_good = [
183+
'1', '2',
184+
'3', '4']; // phpcs:ignore NormalizedArrays.Arrays.CommaAfterLast.MissingMultiLineCloserSameLine
185+
186+
$good = array(
187+
1, 2,
188+
3, 4,);
189+
190+
$good = [
191+
'1', '2',
192+
'3', '4',];
193+
194+
/**
195+
* Tests forbidding a comma after the last array item when the closer is in the same line. See #283.
196+
*/
197+
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine forbid
198+
199+
$found = array(
200+
1, 2,
201+
3, 4,);
202+
203+
$found = [
204+
'1', '2',
205+
'3', '4',];
206+
207+
$found_but_good = [
208+
'1', '2',
209+
'3', '4',]; // phpcs:ignore NormalizedArrays.Arrays.CommaAfterLast.FoundMultiLineCloserSameLine
210+
211+
$good = array(
212+
1, 2,
213+
3, 4);
214+
215+
$good = [
216+
'1', '2',
217+
'3', '4'];
218+
169219
// Reset the properties to the defaults.
170220
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast singleLine forbid
171221
// phpcs:set NormalizedArrays.Arrays.CommaAfterLast multiLine enforce

0 commit comments

Comments
 (0)