Skip to content

Commit e3b2820

Browse files
Refactor
1 parent 3e94438 commit e3b2820

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

src/Differ.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use const PHP_INT_SIZE;
1313
use const PREG_SPLIT_DELIM_CAPTURE;
1414
use const PREG_SPLIT_NO_EMPTY;
15+
use function array_any;
1516
use function array_shift;
1617
use function array_unshift;
1718
use function array_values;
@@ -167,19 +168,11 @@ private function detectUnmatchedLineEndings(array $diff): bool
167168
}
168169

169170
// two-way compare
170-
foreach ($newLineBreaks as $break => $set) {
171-
if (!isset($oldLineBreaks[$break])) {
172-
return true;
173-
}
174-
}
175-
176-
foreach ($oldLineBreaks as $break => $set) {
177-
if (!isset($newLineBreaks[$break])) {
178-
return true;
179-
}
171+
if (array_any($newLineBreaks, static fn (bool $set, string $break) => !isset($oldLineBreaks[$break]))) {
172+
return true;
180173
}
181174

182-
return false;
175+
return array_any($oldLineBreaks, static fn (bool $set, string $break) => !isset($newLineBreaks[$break]));
183176
}
184177

185178
private function getLinebreak(int|string $line): string

tests/Output/AbstractChunkOutputBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function getChunks(array $diff, int $lineThreshold): array
156156

157157
$this->assertSame(
158158
$expected,
159-
$output->getChunks((new Differ(new UnifiedDiffOutputBuilder))->diffToArray($from, $to), $lineThreshold),
159+
$output->getChunks(new Differ(new UnifiedDiffOutputBuilder)->diffToArray($from, $to), $lineThreshold),
160160
);
161161
}
162162
}

tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testIntegrationUsingPHPFileInVendorGitApply(string $fileFrom, st
114114
$from = FileUtils::getFileContent($fileFrom);
115115
$to = FileUtils::getFileContent($fileTo);
116116

117-
$diff = (new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New'])))->diff($from, $to);
117+
$diff = new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New']))->diff($from, $to);
118118

119119
if ('' === $diff && $from === $to) {
120120
// odd case: test after executing as it is more efficient than to read the files and check the contents every time
@@ -132,7 +132,7 @@ public function testIntegrationUsingPHPFileInVendorPatch(string $fileFrom, strin
132132
$from = FileUtils::getFileContent($fileFrom);
133133
$to = FileUtils::getFileContent($fileTo);
134134

135-
$diff = (new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New'])))->diff($from, $to);
135+
$diff = new Differ(new StrictUnifiedDiffOutputBuilder(['fromFile' => 'Original', 'toFile' => 'New']))->diff($from, $to);
136136

137137
if ('' === $diff && $from === $to) {
138138
// odd case: test after executing as it is more efficient than to read the files and check the contents every time

0 commit comments

Comments
 (0)