Skip to content

Commit 064ad5d

Browse files
SpacePossumsebastianbergmann
authored andcommitted
Refactor private methods to match new output interface (to be made).
1 parent 7016891 commit 064ad5d

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Differ.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
4545
$from = $this->validateDiffInput($from);
4646
$to = $this->validateDiffInput($to);
4747
$diff = $this->diffToArray($from, $to, $lcs);
48-
$old = $this->checkIfDiffInOld($diff);
49-
$start = isset($old[0]) ? $old[0] : 0;
50-
$end = \count($diff);
5148

52-
return $this->getBuffer($diff, $old, $start, $end);
49+
return $this->getDiff($diff);
5350
}
5451

5552
/**
@@ -69,14 +66,15 @@ private function validateDiffInput($input): string
6966
}
7067

7168
/**
72-
* Takes input of the diff array and returns the old array.
73-
* Iterates through diff line by line,
69+
* Takes input of the diff array and returns the common parts.
70+
* Iterates through diff line by line.
7471
*
7572
* @param array $diff
73+
* @param int $lineThreshold
7674
*
7775
* @return array
7876
*/
79-
private function checkIfDiffInOld(array $diff): array
77+
private function getCommonChunks(array $diff, int $lineThreshold = 5): array
8078
{
8179
$inOld = false;
8280
$i = 0;
@@ -88,7 +86,7 @@ private function checkIfDiffInOld(array $diff): array
8886
$inOld = $i;
8987
}
9088
} elseif ($inOld !== false) {
91-
if (($i - $inOld) > 5) {
89+
if (($i - $inOld) > $lineThreshold) {
9290
$old[$inOld] = $i - 1;
9391
}
9492

@@ -105,14 +103,15 @@ private function checkIfDiffInOld(array $diff): array
105103
* Generates buffer in string format, returning the patch.
106104
*
107105
* @param array $diff
108-
* @param array $old
109-
* @param int $start
110-
* @param int $end
111106
*
112107
* @return string
113108
*/
114-
private function getBuffer(array $diff, array $old, int $start, int $end): string
109+
private function getDiff(array $diff): string
115110
{
111+
$old = $this->getCommonChunks($diff, 5);
112+
$start = isset($old[0]) ? $old[0] : 0;
113+
$end = \count($diff);
114+
116115
$buffer = $this->header;
117116

118117
if (!isset($old[$start])) {

0 commit comments

Comments
 (0)