Skip to content

Commit

Permalink
Merge pull request #8 from mdeweerd/master
Browse files Browse the repository at this point in the history
Fix Deprecated: Creation of dynamic property + loops for $matches
  • Loading branch information
CloCkWeRX committed Oct 12, 2023
2 parents 4905970 + 2f1fa53 commit d7ef170
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -10,12 +10,13 @@ jobs:
strategy:
matrix:
php:
- 8.3
- 8.2
- 8.1
- 8.0
- 7.4
- 7
- 5.6
- 5.5
- 5.4
- 5.3
os: [ubuntu-latest, ubuntu-22.04]
steps:
- name: Checkout
Expand Down
40 changes: 28 additions & 12 deletions Text/Diff/Engine/native.php
Expand Up @@ -6,9 +6,9 @@
*
* The algorithm used here is mostly lifted from the perl module
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
* http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
* https://cpan.metacpan.org/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
*
* More ideas are taken from: http://www.ics.uci.edu/~eppstein/161/960229.html
* More ideas are taken from: https://www.ics.uci.edu/~eppstein/161/960229.html
*
* Some ideas (and a bit of code) are taken from analyze.c, of GNU
* diffutils-2.7, which can be found at:
Expand All @@ -20,15 +20,26 @@
*
* $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.7.2.5 2009/01/06 15:23:41 jan Exp $
*
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
* Copyright 2004-2009 The Horde Project (https://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
* not receive this file, see https://opensource.org/license/lgpl-3-0/ .
*
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
* @package Text_Diff
*/
class Text_Diff_Engine_native {
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)
{
Expand Down Expand Up @@ -63,9 +74,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 @@ -148,7 +161,7 @@ function diff($from_lines, $to_lines)
* match. The caller must trim matching lines from the beginning and end
* of the portions it is going to specify.
*/
function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
function _diag($xoff, $xlim, $yoff, $ylim, $nchunks)
{
$flip = false;

Expand All @@ -160,6 +173,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 +187,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 +206,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 +228,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 Expand Up @@ -268,7 +284,7 @@ function _lcsPos($ypos)
* Note that XLIM, YLIM are exclusive bounds. All line numbers are
* origin-0 and discarded lines are not counted.
*/
function _compareseq ($xoff, $xlim, $yoff, $ylim)
function _compareseq($xoff, $xlim, $yoff, $ylim)
{
/* Slide down the bottom initial diagonal. */
while ($xoff < $xlim && $yoff < $ylim
Expand Down Expand Up @@ -309,7 +325,7 @@ function _compareseq ($xoff, $xlim, $yoff, $ylim)
reset($seps);
$pt1 = $seps[0];
while ($pt2 = next($seps)) {
$this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
$this->_compareseq($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
$pt1 = $pt2;
}
}
Expand Down

0 comments on commit d7ef170

Please sign in to comment.