Skip to content

Commit a6700d4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feature/improve-sniff-code-error-message
2 parents d0d3449 + ac4987e commit a6700d4

File tree

66 files changed

+304
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+304
-196
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ Add any other context about the problem here.
6666
## Please confirm
6767

6868
- [ ] I have searched the issue list and am not opening a duplicate issue.
69+
- [ ] I have read the [Contribution Guidelines](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/.github/CONTRIBUTING.md) and this is not a [support question](https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions).
6970
- [ ] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
7071
- [ ] I have verified the issue still exists in the `master` branch of PHP_CodeSniffer.

.github/ISSUE_TEMPLATE/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Community Support
4+
url: https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions?discussions_q=-category%3AAnnouncements
5+
about: Support questions belong in Discussions, not in the issue tracker.

.github/ISSUE_TEMPLATE/feature_request.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ code samples of what should *not* be flagged.
2121
## Additional context (optional)
2222
<!-- Add any other context or screenshots about the feature request here. -->
2323

24+
- [ ] I have read the [Contribution Guidelines](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/.github/CONTRIBUTING.md) and this is not a [support question](https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions).
2425
- [ ] I intend to create a pull request to implement this feature.

.github/workflows/label-merge-conflicts.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
push:
66
branches:
77
- master
8+
- 4.0
89
# Check conflicts in new PRs and for resolved conflicts due to an open PR being updated.
910
pull_request_target:
1011
types:
@@ -20,7 +21,8 @@ jobs:
2021
name: Check PRs for merge conflicts
2122

2223
steps:
23-
- uses: mschilde/auto-label-merge-conflicts@master
24+
- name: Check PRs for merge conflicts
25+
uses: eps1lon/actions-label-merge-conflict@v3
2426
with:
25-
CONFLICT_LABEL_NAME: "Status: has merge conflict"
26-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
dirtyLabel: "Status: has merge conflict"
28+
repoToken: ${{ secrets.GITHUB_TOKEN }}

src/Config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ public static function setConfigData($key, $value, $temp=false)
15561556
// standards paths are added to the autoloader.
15571557
if ($key === 'installed_paths') {
15581558
$installedStandards = Standards::getInstalledStandardDetails();
1559-
foreach ($installedStandards as $name => $details) {
1559+
foreach ($installedStandards as $details) {
15601560
Autoload::addSearchPath($details['path'], $details['namespace']);
15611561
}
15621562
}

src/Filters/Filter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function shouldProcessFile($path)
179179
// complete extension list and make sure one is allowed.
180180
$extensions = [];
181181
array_shift($fileParts);
182-
foreach ($fileParts as $part) {
182+
while (empty($fileParts) === false) {
183183
$extensions[implode('.', $fileParts)] = 1;
184184
array_shift($fileParts);
185185
}

src/Reporter.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,29 @@ public function cacheFileReport(File $phpcsFile)
329329
*
330330
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file that has been processed.
331331
*
332-
* @return array
332+
* @return array<string, string|int|array> Prepared report data.
333+
* The format of prepared data is as follows:
334+
* ```
335+
* array(
336+
* 'filename' => string The name of the current file.
337+
* 'errors' => int The number of errors seen in the current file.
338+
* 'warnings' => int The number of warnings seen in the current file.
339+
* 'fixable' => int The number of fixable issues seen in the current file.
340+
* 'messages' => array(
341+
* int <Line number> => array(
342+
* int <Column number> => array(
343+
* int <Message index> => array(
344+
* 'message' => string The error/warning message.
345+
* 'source' => string The full error code for the message.
346+
* 'severity' => int The severity of the message.
347+
* 'fixable' => bool Whether this error/warning is auto-fixable.
348+
* 'type' => string The type of message. Either 'ERROR' or 'WARNING'.
349+
* )
350+
* )
351+
* )
352+
* )
353+
* )
354+
* ```
333355
*/
334356
public function prepareFileReport(File $phpcsFile)
335357
{

src/Reports/Cbf.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ class Cbf implements Report
2828
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2929
* its data should be counted in the grand totals.
3030
*
31-
* @param array $report Prepared report data.
32-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
33-
* @param bool $showSources Show sources?
34-
* @param int $width Maximum allowed line width.
31+
* @param array<string, string|int|array> $report Prepared report data.
32+
* See the {@see Report} interface for a detailed specification.
33+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
34+
* @param bool $showSources Show sources?
35+
* @param int $width Maximum allowed line width.
3536
*
3637
* @return bool
3738
* @throws \PHP_CodeSniffer\Exceptions\DeepExitException

src/Reports/Checkstyle.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class Checkstyle implements Report
2424
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2525
* its data should be counted in the grand totals.
2626
*
27-
* @param array $report Prepared report data.
28-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
29-
* @param bool $showSources Show sources?
30-
* @param int $width Maximum allowed line width.
27+
* @param array<string, string|int|array> $report Prepared report data.
28+
* See the {@see Report} interface for a detailed specification.
29+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
30+
* @param bool $showSources Show sources?
31+
* @param int $width Maximum allowed line width.
3132
*
3233
* @return bool
3334
*/

src/Reports/Code.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class Code implements Report
2525
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2626
* its data should be counted in the grand totals.
2727
*
28-
* @param array $report Prepared report data.
29-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
30-
* @param bool $showSources Show sources?
31-
* @param int $width Maximum allowed line width.
28+
* @param array<string, string|int|array> $report Prepared report data.
29+
* See the {@see Report} interface for a detailed specification.
30+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
31+
* @param bool $showSources Show sources?
32+
* @param int $width Maximum allowed line width.
3233
*
3334
* @return bool
3435
*/
@@ -121,8 +122,8 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
121122

122123
// Determine the longest error message we will be showing.
123124
$maxErrorLength = 0;
124-
foreach ($report['messages'] as $line => $lineErrors) {
125-
foreach ($lineErrors as $column => $colErrors) {
125+
foreach ($report['messages'] as $lineErrors) {
126+
foreach ($lineErrors as $colErrors) {
126127
foreach ($colErrors as $error) {
127128
$length = strlen($error['message']);
128129
if ($showSources === true) {
@@ -264,7 +265,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
264265

265266
echo str_repeat('-', $width).PHP_EOL;
266267

267-
foreach ($lineErrors as $column => $colErrors) {
268+
foreach ($lineErrors as $colErrors) {
268269
foreach ($colErrors as $error) {
269270
$padding = ($maxLineNumLength - strlen($line));
270271
echo 'LINE '.str_repeat(' ', $padding).$line.': ';

src/Reports/Csv.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class Csv implements Report
2222
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2323
* its data should be counted in the grand totals.
2424
*
25-
* @param array $report Prepared report data.
26-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
27-
* @param bool $showSources Show sources?
28-
* @param int $width Maximum allowed line width.
25+
* @param array<string, string|int|array> $report Prepared report data.
26+
* See the {@see Report} interface for a detailed specification.
27+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28+
* @param bool $showSources Show sources?
29+
* @param int $width Maximum allowed line width.
2930
*
3031
* @return bool
3132
*/

src/Reports/Diff.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class Diff implements Report
2222
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2323
* its data should be counted in the grand totals.
2424
*
25-
* @param array $report Prepared report data.
26-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
27-
* @param bool $showSources Show sources?
28-
* @param int $width Maximum allowed line width.
25+
* @param array<string, string|int|array> $report Prepared report data.
26+
* See the {@see Report} interface for a detailed specification.
27+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28+
* @param bool $showSources Show sources?
29+
* @param int $width Maximum allowed line width.
2930
*
3031
* @return bool
3132
*/

src/Reports/Emacs.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class Emacs implements Report
2222
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2323
* its data should be counted in the grand totals.
2424
*
25-
* @param array $report Prepared report data.
26-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
27-
* @param bool $showSources Show sources?
28-
* @param int $width Maximum allowed line width.
25+
* @param array<string, string|int|array> $report Prepared report data.
26+
* See the {@see Report} interface for a detailed specification.
27+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28+
* @param bool $showSources Show sources?
29+
* @param int $width Maximum allowed line width.
2930
*
3031
* @return bool
3132
*/

src/Reports/Full.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class Full implements Report
2323
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2424
* its data should be counted in the grand totals.
2525
*
26-
* @param array $report Prepared report data.
27-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28-
* @param bool $showSources Show sources?
29-
* @param int $width Maximum allowed line width.
26+
* @param array<string, string|int|array> $report Prepared report data.
27+
* See the {@see Report} interface for a detailed specification.
28+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
29+
* @param bool $showSources Show sources?
30+
* @param int $width Maximum allowed line width.
3031
*
3132
* @return bool
3233
*/
@@ -61,8 +62,8 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
6162

6263
// Make sure the report width isn't too big.
6364
$maxErrorLength = 0;
64-
foreach ($report['messages'] as $line => $lineErrors) {
65-
foreach ($lineErrors as $column => $colErrors) {
65+
foreach ($report['messages'] as $lineErrors) {
66+
foreach ($lineErrors as $colErrors) {
6667
foreach ($colErrors as $error) {
6768
// Start with the presumption of a single line error message.
6869
$length = strlen($error['message']);
@@ -138,7 +139,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
138139
$beforeAfterLength = strlen($beforeMsg.$afterMsg);
139140

140141
foreach ($report['messages'] as $line => $lineErrors) {
141-
foreach ($lineErrors as $column => $colErrors) {
142+
foreach ($lineErrors as $colErrors) {
142143
foreach ($colErrors as $error) {
143144
$errorMsg = wordwrap(
144145
$error['message'],

src/Reports/Info.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class Info implements Report
2323
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2424
* its data should be counted in the grand totals.
2525
*
26-
* @param array $report Prepared report data.
27-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28-
* @param bool $showSources Show sources?
29-
* @param int $width Maximum allowed line width.
26+
* @param array<string, string|int|array> $report Prepared report data.
27+
* See the {@see Report} interface for a detailed specification.
28+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
29+
* @param bool $showSources Show sources?
30+
* @param int $width Maximum allowed line width.
3031
*
3132
* @return bool
3233
*/

src/Reports/Json.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class Json implements Report
2323
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2424
* its data should be counted in the grand totals.
2525
*
26-
* @param array $report Prepared report data.
27-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
28-
* @param bool $showSources Show sources?
29-
* @param int $width Maximum allowed line width.
26+
* @param array<string, string|int|array> $report Prepared report data.
27+
* See the {@see Report} interface for a detailed specification.
28+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
29+
* @param bool $showSources Show sources?
30+
* @param int $width Maximum allowed line width.
3031
*
3132
* @return bool
3233
*/

src/Reports/Junit.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class Junit implements Report
2525
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2626
* its data should be counted in the grand totals.
2727
*
28-
* @param array $report Prepared report data.
29-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
30-
* @param bool $showSources Show sources?
31-
* @param int $width Maximum allowed line width.
28+
* @param array<string, string|int|array> $report Prepared report data.
29+
* See the {@see Report} interface for a detailed specification.
30+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
31+
* @param bool $showSources Show sources?
32+
* @param int $width Maximum allowed line width.
3233
*
3334
* @return bool
3435
*/

src/Reports/Notifysend.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ public function __construct()
8888
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
8989
* its data should be counted in the grand totals.
9090
*
91-
* @param array $report Prepared report data.
92-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
93-
* @param bool $showSources Show sources?
94-
* @param int $width Maximum allowed line width.
91+
* @param array<string, string|int|array> $report Prepared report data.
92+
* See the {@see Report} interface for a detailed specification.
93+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
94+
* @param bool $showSources Show sources?
95+
* @param int $width Maximum allowed line width.
9596
*
9697
* @return bool
9798
*/

src/Reports/Performance.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class Performance implements Report
2424
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
2525
* its data should be counted in the grand totals.
2626
*
27-
* @param array $report Prepared report data.
28-
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
29-
* @param bool $showSources Show sources?
30-
* @param int $width Maximum allowed line width.
27+
* @param array<string, string|int|array> $report Prepared report data.
28+
* See the {@see Report} interface for a detailed specification.
29+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being reported on.
30+
* @param bool $showSources Show sources?
31+
* @param int $width Maximum allowed line width.
3132
*
3233
* @return bool
3334
*/

0 commit comments

Comments
 (0)