Skip to content

Commit 2c1bb5d

Browse files
committed
Remove extraneous diffing strategy
1 parent a04647e commit 2c1bb5d

File tree

3 files changed

+2
-117
lines changed

3 files changed

+2
-117
lines changed

lib/Caxy/HtmlDiff/AbstractDiff.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
abstract class AbstractDiff
66
{
7-
const STRATEGY_MATCHING = 'matching';
8-
const STRATEGY_RELATIVE = 'relative';
9-
107
public static $defaultSpecialCaseTags = array('strong', 'b', 'i', 'big', 'small', 'u', 'sub', 'sup', 'strike', 's', 'p');
118
public static $defaultSpecialCaseChars = array('.', ',', '(', ')', '\'');
129
public static $defaultGroupDiffs = true;
@@ -23,9 +20,6 @@ abstract class AbstractDiff
2320
protected $specialCaseChars;
2421
protected $groupDiffs;
2522
protected $matchThreshold = 80;
26-
protected $debug = false;
27-
28-
protected $strategy = self::STRATEGY_MATCHING;
2923

3024
public function __construct($oldText, $newText, $encoding = 'UTF-8', $specialCaseTags = null, $groupDiffs = null)
3125
{
@@ -46,30 +40,6 @@ public function __construct($oldText, $newText, $encoding = 'UTF-8', $specialCas
4640
$this->setSpecialCaseChars(static::$defaultSpecialCaseChars);
4741
}
4842

49-
public function setStrategy($strategy)
50-
{
51-
$this->strategy = $strategy;
52-
53-
return $this;
54-
}
55-
56-
public function getStrategy()
57-
{
58-
return $this->strategy;
59-
}
60-
61-
public function setDebug($debug)
62-
{
63-
$this->debug = $debug;
64-
65-
return $this;
66-
}
67-
68-
public function getDebug()
69-
{
70-
return $this->debug;
71-
}
72-
7343
/**
7444
* @return int
7545
*/

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ protected function diffTables($oldText, $newText)
265265
{
266266
$diff = new TableDiff($oldText, $newText, $this->encoding, $this->specialCaseTags, $this->groupDiffs);
267267
$diff->setMatchThreshold($this->matchThreshold);
268-
$diff->setStrategy($this->strategy);
269268

270269
return $diff->build();
271270
}

lib/Caxy/HtmlDiff/Table/TableDiff.php

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class TableDiff extends AbstractDiff
5656
*/
5757
protected $purifier;
5858

59-
/**
60-
* @var string
61-
*/
62-
protected $strategy = self::STRATEGY_MATCHING;
63-
6459
public function __construct($oldText, $newText, $encoding, $specialCaseTags, $groupDiffs)
6560
{
6661
parent::__construct($oldText, $newText, $encoding, $specialCaseTags, $groupDiffs);
@@ -179,22 +174,8 @@ protected function diffTableContent()
179174
}
180175
}
181176

182-
// new solution for diffing rows
183-
switch ($this->strategy) {
184-
case self::STRATEGY_MATCHING:
185-
$matches = $this->getRowMatches($oldMatchData, $newMatchData);
186-
$this->diffTableRowsWithMatches($oldRows, $newRows, $matches);
187-
break;
188-
189-
case self::STRATEGY_RELATIVE:
190-
$this->diffTableRows($oldRows, $newRows, $oldMatchData);
191-
break;
192-
193-
default:
194-
$matches = $this->getRowMatches($oldMatchData, $newMatchData);
195-
$this->diffTableRowsWithMatches($oldRows, $newRows, $matches);
196-
break;
197-
}
177+
$matches = $this->getRowMatches($oldMatchData, $newMatchData);
178+
$this->diffTableRowsWithMatches($oldRows, $newRows, $matches);
198179

199180
$this->content = $this->htmlFromNode($this->diffTable);
200181
}
@@ -382,71 +363,6 @@ protected function findRowMatch($newMatchData, $startInOld, $endInOld, $startInN
382363
return null;
383364
}
384365

385-
/**
386-
* @param $oldRows
387-
* @param $newRows
388-
* @param $oldMatchData
389-
*/
390-
protected function diffTableRows($oldRows, $newRows, $oldMatchData)
391-
{
392-
$appliedRowSpans = array();
393-
$currentIndexInOld = 0;
394-
$oldCount = count($oldRows);
395-
$newCount = count($newRows);
396-
$difference = max($oldCount, $newCount) - min($oldCount, $newCount);
397-
398-
foreach ($newRows as $newIndex => $row) {
399-
$oldRow = $this->oldTable->getRow($currentIndexInOld);
400-
401-
if ($oldRow) {
402-
$matchPercentage = $oldMatchData[$currentIndexInOld][$newIndex];
403-
404-
// does the old row match better?
405-
$otherMatchBetter = false;
406-
foreach ($oldMatchData[$currentIndexInOld] as $index => $percentage) {
407-
if ($index > $newIndex && $percentage > $matchPercentage) {
408-
$otherMatchBetter = $index;
409-
}
410-
}
411-
412-
if (false !== $otherMatchBetter && $newCount > $oldCount && $difference > 0) {
413-
// insert row as new
414-
$this->diffAndAppendRows(null, $row, $appliedRowSpans);
415-
$difference--;
416-
417-
continue;
418-
}
419-
420-
$nextOldIndex = array_key_exists($currentIndexInOld + 1, $oldRows) ? $currentIndexInOld + 1 : null;
421-
422-
$replacement = false;
423-
424-
if ($nextOldIndex !== null &&
425-
$oldMatchData[$nextOldIndex][$newIndex] > $matchPercentage &&
426-
$oldMatchData[$nextOldIndex][$newIndex] > $this->matchThreshold
427-
) {
428-
// Following row in old is better match, use that.
429-
$this->diffAndAppendRows($oldRows[$currentIndexInOld], null, $appliedRowSpans, true);
430-
431-
$currentIndexInOld++;
432-
$matchPercentage = $oldMatchData[$currentIndexInOld];
433-
$replacement = true;
434-
}
435-
436-
$this->diffAndAppendRows($oldRows[$currentIndexInOld], $row, $appliedRowSpans, $replacement);
437-
$currentIndexInOld++;
438-
} else {
439-
$this->diffAndAppendRows(null, $row, $appliedRowSpans);
440-
}
441-
}
442-
443-
if (count($oldRows) > count($newRows)) {
444-
foreach (array_slice($oldRows, count($newRows)) as $row) {
445-
$this->diffAndAppendRows($row, null, $appliedRowSpans);
446-
}
447-
}
448-
}
449-
450366
/**
451367
* @param TableRow|null $oldRow
452368
* @param TableRow|null $newRow

0 commit comments

Comments
 (0)