Skip to content

Commit

Permalink
Port PHP compatibility fixes from pear/Text_Diff#8 preventing "Creati…
Browse files Browse the repository at this point in the history
…on of dynamic property Text_Diff_Engine_native::$xchanged is deprecated" on PHP 8.2
  • Loading branch information
marcovtwout committed Sep 27, 2023
1 parent 2a0e947 commit 72d8ed2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions framework/gii/components/Pear/Text/Diff/Engine/native.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
*/
class Text_Diff_Engine_native {

public $xchanged;
public $ychanged;
public $xv;
public $yv;
public $xind;
public $yind;
public $seq;
public $in_seq;
public $lcs;

function diff($from_lines, $to_lines)
{
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
Expand Down Expand Up @@ -63,9 +73,11 @@ function diff($from_lines, $to_lines)
}

// Ignore lines which do not exist in both files.
$xhash = [];
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
$xhash[$from_lines[$xi]] = 1;
}
$yhash = [];
for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
$line = $to_lines[$yi];
if (($this->ychanged[$yi] = empty($xhash[$line]))) {
Expand Down Expand Up @@ -160,6 +172,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
= array($yoff, $ylim, $xoff, $xlim);
}

$ymatches = array();
if ($flip) {
for ($i = $ylim - 1; $i >= $yoff; $i--) {
$ymatches[$this->xv[$i]][] = $i;
Expand All @@ -173,7 +186,7 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
$this->lcs = 0;
$this->seq[0]= $yoff - 1;
$this->in_seq = array();
$ymids[0] = array();
$ymids = array(array());

$numer = $xlim - $xoff + $nchunks - 1;
$x = $xoff;
Expand All @@ -192,15 +205,16 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
}
$matches = $ymatches[$line];
reset($matches);
foreach ($matches as list(, $y)) {
while ($y = current($matches)) {
if (empty($this->in_seq[$y])) {
$k = $this->_lcsPos($y);
assert($k > 0);
$ymids[$k] = $ymids[$k - 1];
break;
}
next($matches);
}
foreach ($matches as list(, $y)) {
while ($y = current($matches)) {
if ($y > $this->seq[$k - 1]) {
assert($y <= $this->seq[$k]);
/* Optimization: this is a common case: next match is
Expand All @@ -213,11 +227,12 @@ function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
assert($k > 0);
$ymids[$k] = $ymids[$k - 1];
}
next($matches);
}
}
}

$seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
$seps = array($flip ? array($yoff, $xoff) : array($xoff, $yoff));
$ymid = $ymids[$this->lcs];
for ($n = 0; $n < $nchunks - 1; $n++) {
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
Expand Down

0 comments on commit 72d8ed2

Please sign in to comment.