Skip to content

Commit 0fa4b45

Browse files
committed
Improve duplicate check code
1 parent b8da742 commit 0fa4b45

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Analyzers/DuplicateAnalyzer.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,16 @@ protected function processLines(SplFileObject $file)
7171
$trimLine = trim($line);
7272
$lineNo = ($file->key() + 1);
7373

74-
if ($foundIndex = array_search($trimLine, array_column($lines, 'code'))) {
75-
$foundLineNo = $lines[$foundIndex]['lineNo'];
74+
if (isset($lines[$trimLine])) {
75+
$foundLineNo = $lines[$trimLine];
7676
if (!in_array($foundLineNo, $duplicates)) {
7777
$duplicates[] = $foundLineNo;
7878
}
79-
$duplicates[] = $lineNo;
80-
}
8179

82-
if (strlen($trimLine) > 3) {
83-
$lines[] = [
84-
'lineNo' => $lineNo,
85-
'code' => $trimLine,
86-
];
80+
$duplicates[] = $lineNo;
81+
} else if (strlen($trimLine) > 3) {
82+
// Non duplicate first line
83+
$lines[$trimLine] = $lineNo;
8784
}
8885
}
8986

0 commit comments

Comments
 (0)