Merge "Special:PagesWithProp: Distinguish content from interface"
[lhc/web/wiklou.git] / includes / diff / WikiDiff3.php
index 8def296..ea6f6e5 100644 (file)
@@ -29,7 +29,7 @@
  * (http://citeseer.ist.psu.edu/myers86ond.html) with range compression (see Wu et al.'s
  * "An O(NP) Sequence Comparison Algorithm").
  *
- * This implementation supports an upper bound on the excution time.
+ * This implementation supports an upper bound on the execution time.
  *
  * Complexity: O((M + N)D) worst case time, O(M + N + D^2) expected time, O(M + N) space
  *
@@ -64,7 +64,7 @@ class WikiDiff3 {
 
        public function diff( /*array*/ $from, /*array*/ $to ) {
                // remember initial lengths
-               $m = sizeof( $from );
+               $m = count( $from );
                $n = count( $to );
 
                $this->heuristicUsed = false;
@@ -239,7 +239,7 @@ class WikiDiff3 {
                                                        $starty - 1, $V, $snake )
                        + $this->lcs_rec( $startx + $len, $topl1, $starty + $len,
                                                        $topl2, $V, $snake );
-               } else if ( $d == 1 ) {
+               } elseif ( $d == 1 ) {
                        /*
                         * In this case the sequences differ by exactly 1 line. We have
                         * already saved all the lines after the difference in the for loop
@@ -332,7 +332,7 @@ class WikiDiff3 {
                                        // check to see if we can cut down the diagonal range
                                        if ( $x >= $N && $end_forward > $k - 1 ) {
                                                $end_forward = $k - 1;
-                                       } else if ( $absy - $bottoml2 >= $M ) {
+                                       } elseif ( $absy - $bottoml2 >= $M ) {
                                                $start_forward = $k + 1;
                                                $value_to_add_forward = 0;
                                        }
@@ -366,7 +366,7 @@ class WikiDiff3 {
                                        if ( $x <= 0 ) {
                                                $start_backward = $k + 1;
                                                $value_to_add_backward = 0;
-                                       } else if ( $y <= 0 && $end_backward > $k - 1 ) {
+                                       } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
                                                $end_backward = $k - 1;
                                        }
                                }
@@ -400,7 +400,7 @@ class WikiDiff3 {
                                        // check to see if we can cut down the diagonal range
                                        if ( $x >= $N && $end_forward > $k - 1 ) {
                                                $end_forward = $k - 1;
-                                       } else if ( $absy -$bottoml2 >= $M ) {
+                                       } elseif ( $absy -$bottoml2 >= $M ) {
                                                $start_forward = $k + 1;
                                                $value_to_add_forward = 0;
                                        }
@@ -441,7 +441,7 @@ class WikiDiff3 {
                                        if ( $x <= 0 ) {
                                                $start_backward = $k + 1;
                                                $value_to_add_backward = 0;
-                                       } else if ( $y <= 0 && $end_backward > $k - 1 ) {
+                                       } elseif ( $y <= 0 && $end_backward > $k - 1 ) {
                                                $end_backward = $k - 1;
                                        }
                                }
@@ -490,7 +490,6 @@ class WikiDiff3 {
 
                $temp = array( 0, 0, 0 );
 
-
                $max_progress = array_fill( 0, ceil( max( $forward_end_diag - $forward_start_diag,
                                $backward_end_diag - $backward_start_diag ) / 2 ), $temp );
                $num_progress = 0; // the 1st entry is current, it is initialized
@@ -510,7 +509,7 @@ class WikiDiff3 {
                                $max_progress[0][0] = $x;
                                $max_progress[0][1] = $y;
                                $max_progress[0][2] = $progress;
-                       } else if ( $progress == $max_progress[0][2] ) {
+                       } elseif ( $progress == $max_progress[0][2] ) {
                                ++$num_progress;
                                $max_progress[$num_progress][0] = $x;
                                $max_progress[$num_progress][1] = $y;
@@ -537,7 +536,7 @@ class WikiDiff3 {
                                $max_progress[0][0] = $x;
                                $max_progress[0][1] = $y;
                                $max_progress[0][2] = $progress;
-                       } else if ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
+                       } elseif ( $progress == $max_progress[0][2] && !$max_progress_forward ) {
                                ++$num_progress;
                                $max_progress[$num_progress][0] = $x;
                                $max_progress[$num_progress][1] = $y;
@@ -546,9 +545,12 @@ class WikiDiff3 {
                }
 
                // return the middle diagonal with maximal progress.
-               return $max_progress[floor( $num_progress / 2 )];
+               return $max_progress[(int)floor( $num_progress / 2 )];
        }
 
+       /**
+        * @return mixed
+        */
        public function getLcsLength() {
                if ( $this->heuristicUsed && !$this->lcsLengthCorrectedForHeuristic ) {
                        $this->lcsLengthCorrectedForHeuristic = true;