@@ -66,54 +66,54 @@ private function isSeparator($s)
6666 private function _calcDistance ($ s1 , $ s2 , $ keepMatrix )
6767 {
6868 // normalize the input
69- $ s1 = $ this ->split ($ s1 );
70- $ s2 = $ this ->split ($ s2 );
69+ $ parts1 = $ this ->split ($ s1 );
70+ $ parts2 = $ this ->split ($ s2 );
7171
7272 // reset the matrix
7373 $ m =& $ this ->matrix ;
7474 $ m = [];
7575
7676 // temporary variables
77- $ n1 = count ($ s1 );
78- $ n2 = count ($ s2 );
77+ $ n1 = count ($ parts1 );
78+ $ n2 = count ($ parts2 );
7979
8080 // check for perfect equality
81- if ($ s1 === $ s2 ) {
81+ if ($ parts1 === $ parts2 ) {
8282 $ this ->startMatch = $ n1 ;
8383 $ this ->endMatch = 0 ;
8484 return 0 ;
8585 }
8686
8787 // check for trailing equality
88- for ($ this ->startMatch = 0 ; $ this ->startMatch < $ n1 && $ this ->startMatch < $ n2 && $ s1 [$ this ->startMatch ] === $ s2 [$ this ->startMatch ]; $ this ->startMatch ++) { }
88+ for ($ this ->startMatch = 0 ; $ this ->startMatch < $ n1 && $ this ->startMatch < $ n2 && $ parts1 [$ this ->startMatch ] === $ parts2 [$ this ->startMatch ]; $ this ->startMatch ++) { }
8989 if ($ this ->startMatch ) {
90- $ s1 = array_slice ($ s1 , $ this ->startMatch );
90+ $ parts1 = array_slice ($ parts1 , $ this ->startMatch );
9191 $ n1 -= $ this ->startMatch ;
92- $ s2 = array_slice ($ s2 , $ this ->startMatch );
92+ $ parts2 = array_slice ($ parts2 , $ this ->startMatch );
9393 $ n2 -= $ this ->startMatch ;
9494 }
95- for ($ this ->endMatch = 0 ; $ this ->endMatch < $ n1 && $ this ->endMatch < $ n2 && $ s1 [$ n1 - 1 - $ this ->endMatch ] === $ s2 [$ n2 - 1 - $ this ->endMatch ]; $ this ->endMatch ++) { }
95+ for ($ this ->endMatch = 0 ; $ this ->endMatch < $ n1 && $ this ->endMatch < $ n2 && $ parts1 [$ n1 - 1 - $ this ->endMatch ] === $ parts2 [$ n2 - 1 - $ this ->endMatch ]; $ this ->endMatch ++) { }
9696 if ($ this ->endMatch ) {
97- $ s1 = array_slice ($ s1 , 0 , -$ this ->endMatch );
97+ $ parts1 = array_slice ($ parts1 , 0 , -$ this ->endMatch );
9898 $ n1 -= $ this ->endMatch ;
99- $ s2 = array_slice ($ s2 , 0 , -$ this ->endMatch );
99+ $ parts2 = array_slice ($ parts2 , 0 , -$ this ->endMatch );
100100 $ n2 -= $ this ->endMatch ;
101101 }
102102
103103 // init the first row
104104 $ m [0 ][0 ] = 0 ;
105105 for ($ i2 = 0 ; $ i2 < $ n2 ; $ i2 ++) {
106- $ m [0 ][$ i2 + 1 ] = $ m [0 ][$ i2 ] + $ this ->operationCostCalculator ->getInsertCost ($ s2 [$ i2 ]);
106+ $ m [0 ][$ i2 + 1 ] = $ m [0 ][$ i2 ] + $ this ->operationCostCalculator ->getInsertCost ($ parts2 [$ i2 ]);
107107 }
108108
109109 // calc the matrix row by row
110110 for ($ i1 = 0 ; $ i1 < $ n1 ; $ i1 ++) {
111- $ c1 = $ s1 [$ i1 ];
111+ $ c1 = $ parts1 [$ i1 ];
112112 $ deleteCost = $ this ->operationCostCalculator ->getDeleteCost ($ c1 );
113113 $ m [$ i1 + 1 ][0 ] = $ m [$ i1 ][0 ] + $ deleteCost ;
114114
115115 for ($ i2 = 0 ; $ i2 < $ n2 ; $ i2 ++) {
116- $ c2 = $ s2 [$ i2 ];
116+ $ c2 = $ parts2 [$ i2 ];
117117 $ insertCost = $ this ->operationCostCalculator ->getInsertCost ($ c2 );
118118 $ replaceCost = $ this ->operationCostCalculator ->getReplaceCost ($ c1 , $ c2 );
119119 $ m [$ i1 + 1 ][$ i2 + 1 ] = min (
@@ -153,41 +153,41 @@ public function calcDistance($s1, $s2)
153153 public function calcDiff ($ s1 , $ s2 )
154154 {
155155 // normalize the input
156- $ s1 = $ this ->split ($ s1 );
157- $ s2 = $ this ->split ($ s2 );
156+ $ parts1 = $ this ->split ($ s1 );
157+ $ parts2 = $ this ->split ($ s2 );
158158
159159 // calc the distance and the matrix
160- $ distance = $ this ->_calcDistance ($ s1 , $ s2 , true );
160+ $ distance = $ this ->_calcDistance ($ parts1 , $ parts2 , true );
161161
162162 // temporary variables
163163 $ m = $ this ->matrix ;
164- $ n1 = count ($ s1 );
165- $ n2 = count ($ s2 );
164+ $ n1 = count ($ parts1 );
165+ $ n2 = count ($ parts2 );
166166
167167 // check if calcDistance identified perfect or partial equality
168168 $ startDiff = [];
169169 if ($ this ->startMatch ) {
170- $ startDiff [] = new StringDiffOperation (StringDiffOperation::MATCH , implode ('' , array_slice ($ s1 , 0 , $ this ->startMatch )));
171- $ s1 = array_slice ($ s1 , $ this ->startMatch );
170+ $ startDiff [] = new StringDiffOperation (StringDiffOperation::MATCH , implode ('' , array_slice ($ parts1 , 0 , $ this ->startMatch )));
171+ $ parts1 = array_slice ($ parts1 , $ this ->startMatch );
172172 $ n1 -= $ this ->startMatch ;
173- $ s2 = array_slice ($ s2 , $ this ->startMatch );
173+ $ parts2 = array_slice ($ parts2 , $ this ->startMatch );
174174 $ n2 -= $ this ->startMatch ;
175175 }
176176 $ endDiff = [];
177177 if ($ this ->endMatch ) {
178- $ endDiff [] = new StringDiffOperation (StringDiffOperation::MATCH , implode ('' , array_slice ($ s1 , -$ this ->endMatch )));
179- $ s1 = array_slice ($ s1 , 0 , -$ this ->endMatch );
178+ $ endDiff [] = new StringDiffOperation (StringDiffOperation::MATCH , implode ('' , array_slice ($ parts1 , -$ this ->endMatch )));
179+ $ parts1 = array_slice ($ parts1 , 0 , -$ this ->endMatch );
180180 $ n1 -= $ this ->endMatch ;
181- $ s2 = array_slice ($ s2 , 0 , -$ this ->endMatch );
181+ $ parts2 = array_slice ($ parts2 , 0 , -$ this ->endMatch );
182182 $ n2 -= $ this ->endMatch ;
183183 }
184184
185185 $ diff = [];
186186 $ i1 = $ n1 ;
187187 $ i2 = $ n2 ;
188188 while ($ i1 || $ i2 ) {
189- $ c1 = $ i1 ? $ s1 [$ i1 - 1 ] : null ;
190- $ c2 = $ i2 ? $ s2 [$ i2 - 1 ] : null ;
189+ $ c1 = $ i1 ? $ parts1 [$ i1 - 1 ] : null ;
190+ $ c2 = $ i2 ? $ parts2 [$ i2 - 1 ] : null ;
191191 $ insertCost = $ i2 ? $ m [$ i1 ][$ i2 - 1 ] + $ this ->operationCostCalculator ->getInsertCost ($ c2 ) : PHP_INT_MAX ;
192192 $ deleteCost = $ i1 ? $ m [$ i1 - 1 ][$ i2 ] + $ this ->operationCostCalculator ->getDeleteCost ($ c1 ) : PHP_INT_MAX ;
193193 $ replaceCost = ($ i1 && $ i2 ) ? $ m [$ i1 - 1 ][$ i2 - 1 ] + $ this ->operationCostCalculator ->getReplaceCost ($ c1 , $ c2 ) : PHP_INT_MAX ;
0 commit comments