Skip to content

Commit aa1be7d

Browse files
janedbalclaude
andcommitted
Add support for multiple identifiers in ignoreErrors configuration
- Update parametersSchema.neon to support 'identifiers' array field - Modify IgnoredErrorHelper to expand identifiers array into separate rules - Update IgnoredError::stringifyPattern() to display multiple identifiers - Add comprehensive tests for identifiers array functionality - Update IgnoreErrorsTest to reflect new configuration entries Resolves #13015 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 599ac2b commit aa1be7d

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

conf/parametersSchema.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ parametersSchema:
109109
structure([
110110
?messages: listOf(string())
111111
?identifier: string()
112+
?identifiers: listOf(string())
112113
?path: string()
113114
?reportUnmatched: bool()
114115
]),
115116
structure([
116117
?message: string()
117118
?identifier: string()
119+
?identifiers: listOf(string())
118120
?path: string()
119121
?reportUnmatched: bool()
120122
]),
@@ -123,18 +125,21 @@ parametersSchema:
123125
count: int()
124126
path: string()
125127
?identifier: string()
128+
?identifiers: listOf(string())
126129
?reportUnmatched: bool()
127130
]),
128131
structure([
129132
?message: string()
130133
paths: listOf(string())
131134
?identifier: string()
135+
?identifiers: listOf(string())
132136
?reportUnmatched: bool()
133137
]),
134138
structure([
135139
?messages: listOf(string())
136140
paths: listOf(string())
137141
?identifier: string()
142+
?identifiers: listOf(string())
138143
?reportUnmatched: bool()
139144
])
140145
)

src/Analyser/Ignore/IgnoredError.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public static function stringifyPattern($ignoredError): string
3737
} else {
3838
$message = sprintf('%s (%s)', $message, $ignoredError['identifier']);
3939
}
40+
} elseif (isset($ignoredError['identifiers'])) {
41+
$identifierList = implode(', ', $ignoredError['identifiers']);
42+
if ($message === '') {
43+
$message = $identifierList;
44+
} else {
45+
$message = sprintf('%s (%s)', $message, $identifierList);
46+
}
4047
}
4148

4249
if ($message === '') {

src/Analyser/Ignore/IgnoredErrorHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function initialize(): IgnoredErrorHelperResult
4040
$expandedIgnoreErrors = [];
4141
foreach ($this->ignoreErrors as $ignoreError) {
4242
if (is_array($ignoreError)) {
43-
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['identifier'])) {
43+
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['identifier']) && !isset($ignoreError['identifiers'])) {
4444
$errors[] = sprintf(
4545
'Ignored error %s is missing a message or an identifier.',
4646
Json::encode($ignoreError),
@@ -54,6 +54,13 @@ public function initialize(): IgnoredErrorHelperResult
5454
$expandedIgnoreError['message'] = $message;
5555
$expandedIgnoreErrors[] = $expandedIgnoreError;
5656
}
57+
} elseif (isset($ignoreError['identifiers'])) {
58+
foreach ($ignoreError['identifiers'] as $identifier) {
59+
$expandedIgnoreError = $ignoreError;
60+
unset($expandedIgnoreError['identifiers']);
61+
$expandedIgnoreError['identifier'] = $identifier;
62+
$expandedIgnoreErrors[] = $expandedIgnoreError;
63+
}
5764
} else {
5865
$expandedIgnoreErrors[] = $ignoreError;
5966
}

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ public function testFileWithAnIgnoredErrorMessages(): void
116116
$this->assertEquals([], $result);
117117
}
118118

119+
public function testFileWithAnIgnoredErrorIdentifiers(): void
120+
{
121+
$result = $this->runAnalyser([['identifiers' => ['tests.alwaysFail']]], true, __DIR__ . '/data/bootstrap-error.php', false);
122+
$this->assertEmpty($result);
123+
}
124+
125+
public function testFileWithAnIgnoredErrorIdentifiersWithPath(): void
126+
{
127+
$result = $this->runAnalyser([['identifiers' => ['tests.alwaysFail'], 'path' => __DIR__ . '/data/bootstrap-error.php']], true, __DIR__ . '/data/bootstrap-error.php', false);
128+
$this->assertEmpty($result);
129+
}
130+
131+
public function testFileWithAnIgnoredErrorIdentifiersWithWrongIdentifier(): void
132+
{
133+
$result = $this->runAnalyser([['identifiers' => ['wrong.identifier']]], true, __DIR__ . '/data/bootstrap-error.php', false);
134+
$this->assertCount(2, $result);
135+
assert($result[0] instanceof Error);
136+
$this->assertSame('Fail.', $result[0]->getMessage());
137+
assert(is_string($result[1]));
138+
$this->assertSame('Ignored error pattern wrong.identifier was not matched in reported errors.', $result[1]);
139+
}
140+
119141
public function testIgnoringBrokenConfigurationDoesNotWork(): void
120142
{
121143
$this->markTestIncomplete();

tests/PHPStan/DependencyInjection/IgnoreErrorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class IgnoreErrorsTest extends PHPStanTestCase
99

1010
public function testIgnoreErrors(): void
1111
{
12-
$this->assertCount(12, self::getContainer()->getParameter('ignoreErrors'));
12+
$this->assertCount(16, self::getContainer()->getParameter('ignoreErrors'));
1313
}
1414

1515
/**

tests/PHPStan/DependencyInjection/ignoreErrors.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ parameters:
4545
paths:
4646
- '/dir/*'
4747
reportUnmatched: false
48+
-
49+
identifiers:
50+
- 'error.identifier'
51+
-
52+
identifiers:
53+
- 'error.identifier'
54+
path: '/dir/*'
55+
-
56+
identifiers:
57+
- 'error.identifier'
58+
paths:
59+
- '/dir/*'
60+
-
61+
identifiers:
62+
- 'error.identifier'
63+
- 'another.identifier'
64+
path: '/dir/*'
65+
reportUnmatched: false

0 commit comments

Comments
 (0)