@@ -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