diff --git a/src/Contract/Analyser/EventHelper.php b/src/Contract/Analyser/EventHelper.php index c6d649157..a4c937044 100644 --- a/src/Contract/Analyser/EventHelper.php +++ b/src/Contract/Analyser/EventHelper.php @@ -33,15 +33,16 @@ public function __construct( */ 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); + + 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; } diff --git a/tests/Contract/Analyser/EventHelperTest.php b/tests/Contract/Analyser/EventHelperTest.php index 713db5921..5e605e70d 100644 --- a/tests/Contract/Analyser/EventHelperTest.php +++ b/tests/Contract/Analyser/EventHelperTest.php @@ -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(), @@ -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(),