Skip to content

Commit 2d1114d

Browse files
Junade Alisebastianbergmann
authored andcommitted
Extracted detectUnmatchedLineEndings function out of if statement in diffToArray.
1 parent 2c69dc2 commit 2d1114d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Differ.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
218218
$common = $lcs->calculate(array_values($from), array_values($to));
219219
$diff = array();
220220

221-
if (isset($fromMatches[0]) && $toMatches[0] &&
222-
count($fromMatches[0]) === count($toMatches[0]) &&
223-
$fromMatches[0] !== $toMatches[0]
224-
) {
221+
if ($this->detectUnmatchedLineEndings($fromMatches, $toMatches)) {
225222
$diff[] = array(
226223
'#Warning: Strings contain different line endings!',
227224
0
@@ -334,7 +331,7 @@ private function calculateEstimatedFootprint(array $from, array $to)
334331

335332
/**
336333
* Adjust start point and removes common from/to lines.
337-
*
334+
*
338335
* @param $length
339336
* @param $from
340337
* @param $to
@@ -374,4 +371,19 @@ private function adjustDiffEndPoint(&$length, &$from, &$to, $end, $fromLength, $
374371
}
375372
}
376373
}
374+
375+
/**
376+
* Returns true if line ends don't match on fromMatches and toMatches.
377+
*
378+
* @param $fromMatches
379+
* @param $toMatches
380+
*
381+
* @return bool
382+
*/
383+
private function detectUnmatchedLineEndings($fromMatches, $toMatches)
384+
{
385+
return isset($fromMatches[0]) && $toMatches[0] &&
386+
count($fromMatches[0]) === count($toMatches[0]) &&
387+
$fromMatches[0] !== $toMatches[0];
388+
}
377389
}

0 commit comments

Comments
 (0)