Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1226 - skipped multiple violations in one file #1227

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Contract/Analyser/EventHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
*/
public function shouldViolationBeSkipped(string $depender, string $dependent): bool
{
if (!array_key_exists($depender, $this->skippedViolations)) {
return false;
}
$key = array_search($dependent, $this->unmatchedSkippedViolation[$depender], true);
if (false === $key) {
$skippedViolation = $this->skippedViolations[$depender] ?? [];
$matched = [] !== $skippedViolation && in_array($dependent, $skippedViolation, true);

Check warning on line 37 in src/Contract/Analyser/EventHelper.php

View workflow job for this annotation

GitHub Actions / infection (ubuntu-20.04, 8.1)

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ public function shouldViolationBeSkipped(string $depender, string $dependent) : bool { $skippedViolation = $this->skippedViolations[$depender] ?? []; - $matched = [] !== $skippedViolation && in_array($dependent, $skippedViolation, true); + $matched = [] !== $skippedViolation || in_array($dependent, $skippedViolation, true); if (!$matched) { return false; }

if (!$matched) {
return false;
}

unset($this->unmatchedSkippedViolation[$depender][$key]);
if (false !== ($key = array_search($dependent, $this->unmatchedSkippedViolation[$depender], true))) {
unset($this->unmatchedSkippedViolation[$depender][$key]);
}

return true;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Contract/Analyser/EventHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public function testIsViolationSkipped(): void
];
$helper = new EventHelper($configuration, new LayerProvider([]));

self::assertTrue(
$helper->shouldViolationBeSkipped(
ClassLikeToken::fromFQCN('ClassWithOneDep')->toString(),
ClassLikeToken::fromFQCN('DependencyClass')->toString()
)
);
// also skips multiple occurrences
self::assertTrue(
$helper->shouldViolationBeSkipped(
ClassLikeToken::fromFQCN('ClassWithOneDep')->toString(),
Expand Down Expand Up @@ -73,6 +80,13 @@ public function testUnmatchedSkippedViolations(): void
];
$helper = new EventHelper($configuration, new LayerProvider([]));

self::assertTrue(
$helper->shouldViolationBeSkipped(
ClassLikeToken::fromFQCN('ClassWithOneDep')->toString(),
ClassLikeToken::fromFQCN('DependencyClass')->toString()
)
);
// also skips multiple occurrences
self::assertTrue(
$helper->shouldViolationBeSkipped(
ClassLikeToken::fromFQCN('ClassWithOneDep')->toString(),
Expand Down
Loading