@@ -71,38 +71,43 @@ class HtmlArray extends RendererAbstract
7171 * into string at the given start offset.
7272 * @return string|array The result string is returned. If string is an array then array is returned.
7373 */
74- public function mb_substr_replace ($ string , $ replacement , $ start , $ length =NULL ) {
74+ public function mbSubstrReplace ($ string , $ replacement , $ start , $ length = null )
75+ {
7576 if (is_array ($ string )) {
7677 $ num = count ($ string );
7778 // $replacement
78- $ replacement = is_array ($ replacement ) ? array_slice ($ replacement , 0 , $ num ) : array_pad (array ($ replacement ), $ num , $ replacement );
79+ if (is_array ($ replacement )) {
80+ $ replacement = array_slice ($ replacement , 0 , $ num );
81+ } else {
82+ $ replacement = array_pad (array ($ replacement ), $ num , $ replacement );
83+ }
84+
7985 // $start
8086 if (is_array ($ start )) {
8187 $ start = array_slice ($ start , 0 , $ num );
8288 foreach ($ start as $ key => $ value )
8389 $ start [$ key ] = is_int ($ value ) ? $ value : 0 ;
84- }
85- else {
90+ } else {
8691 $ start = array_pad (array ($ start ), $ num , $ start );
8792 }
8893 // $length
8994 if (!isset ($ length )) {
9095 $ length = array_fill (0 , $ num , 0 );
91- }
92- elseif (is_array ($ length )) {
96+ } elseif (is_array ($ length )) {
9397 $ length = array_slice ($ length , 0 , $ num );
9498 foreach ($ length as $ key => $ value )
9599 $ length [$ key ] = isset ($ value ) ? (is_int ($ value ) ? $ value : $ num ) : 0 ;
96- }
97- else {
100+ } else {
98101 $ length = array_pad (array ($ length ), $ num , $ length );
99102 }
100103 // Recursive call
101- return array_map (array ($ this , 'mb_substr_replace ' ), $ string , $ replacement , $ start , $ length );
104+ return array_map (array ($ this , 'mbSubstrReplace ' ), $ string , $ replacement , $ start , $ length );
102105 }
103106 preg_match_all ('/./us ' , (string )$ string , $ smatches );
104107 preg_match_all ('/./us ' , (string )$ replacement , $ rmatches );
105- if ($ length === NULL ) $ length = mb_strlen ($ string );
108+ if ($ length === null ) {
109+ $ length = mb_strlen ($ string );
110+ }
106111 array_splice ($ smatches ['0 ' ], $ start , $ length , $ rmatches [0 ]);
107112 return join ($ smatches ['0 ' ]);
108113 }
@@ -124,20 +129,20 @@ public function render()
124129
125130 $ changes = array ();
126131 $ opCodes = $ this ->diff ->getGroupedOpcodes ();
127- foreach ($ opCodes as $ group ) {
132+ foreach ($ opCodes as $ group ) {
128133 $ blocks = array ();
129134 $ lastTag = null ;
130135 $ lastBlock = 0 ;
131- foreach ($ group as $ code ) {
136+ foreach ($ group as $ code ) {
132137 list ($ tag , $ i1 , $ i2 , $ j1 , $ j2 ) = $ code ;
133138
134- if ($ tag == 'replace ' && $ i2 - $ i1 == $ j2 - $ j1 ) {
135- for ($ i = 0 ; $ i < ($ i2 - $ i1 ); ++$ i ) {
139+ if ($ tag == 'replace ' && $ i2 - $ i1 == $ j2 - $ j1 ) {
140+ for ($ i = 0 ; $ i < ($ i2 - $ i1 ); ++$ i ) {
136141 $ fromLine = $ a [$ i1 + $ i ];
137142 $ toLine = $ b [$ j1 + $ i ];
138143
139144 list ($ start , $ end ) = $ this ->getChangeExtent ($ fromLine , $ toLine );
140- if ($ start != 0 || $ end != 0 ) {
145+ if ($ start != 0 || $ end != 0 ) {
141146 $ realEnd = mb_strlen ($ fromLine ) + $ end ;
142147
143148 $ fromLine = mb_substr ($ fromLine , 0 , $ start ) . "\0" .
@@ -155,28 +160,27 @@ public function render()
155160 }
156161 }
157162
158- if ($ tag != $ lastTag ) {
163+ if ($ tag != $ lastTag ) {
159164 $ blocks [] = $ this ->getDefaultArray ($ tag , $ i1 , $ j1 );
160165 $ lastBlock = count ($ blocks )-1 ;
161166 }
162167
163168 $ lastTag = $ tag ;
164169
165- if ($ tag == 'equal ' ) {
170+ if ($ tag == 'equal ' ) {
166171 $ lines = array_slice ($ a , $ i1 , ($ i2 - $ i1 ));
167172 $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ this ->formatLines ($ lines );
168173 $ lines = array_slice ($ b , $ j1 , ($ j2 - $ j1 ));
169174 $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ this ->formatLines ($ lines );
170- }
171- else {
172- if ($ tag == 'replace ' || $ tag == 'delete ' ) {
175+ } else {
176+ if ($ tag == 'replace ' || $ tag == 'delete ' ) {
173177 $ lines = array_slice ($ a , $ i1 , ($ i2 - $ i1 ));
174178 $ lines = $ this ->formatLines ($ lines );
175179 $ lines = str_replace (array ("\0" , "\1" ), array ('<del> ' , '</del> ' ), $ lines );
176180 $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ lines ;
177181 }
178182
179- if ($ tag == 'replace ' || $ tag == 'insert ' ) {
183+ if ($ tag == 'replace ' || $ tag == 'insert ' ) {
180184 $ lines = array_slice ($ b , $ j1 , ($ j2 - $ j1 ));
181185 $ lines = $ this ->formatLines ($ lines );
182186 $ lines = str_replace (array ("\0" , "\1" ), array ('<ins> ' , '</ins> ' ), $ lines );
@@ -201,12 +205,12 @@ private function getChangeExtent($fromLine, $toLine)
201205 {
202206 $ start = 0 ;
203207 $ limit = min (mb_strlen ($ fromLine ), mb_strlen ($ toLine ));
204- while ($ start < $ limit && mb_substr ($ fromLine , $ start , 1 ) == mb_substr ($ toLine , $ start , 1 )) {
208+ while ($ start < $ limit && mb_substr ($ fromLine , $ start , 1 ) == mb_substr ($ toLine , $ start , 1 )) {
205209 ++$ start ;
206210 }
207211 $ end = -1 ;
208212 $ limit = $ limit - $ start ;
209- while (-$ end <= $ limit && mb_substr ($ fromLine , $ end , 1 ) == mb_substr ($ toLine , $ end , 1 )) {
213+ while (-$ end <= $ limit && mb_substr ($ fromLine , $ end , 1 ) == mb_substr ($ toLine , $ end , 1 )) {
210214 --$ end ;
211215 }
212216 return array (
@@ -229,7 +233,7 @@ protected function formatLines($lines)
229233 $ lines = array_map (array ($ this , 'ExpandTabs ' ), $ lines );
230234 }
231235 $ lines = array_map (array ($ this , 'HtmlSafe ' ), $ lines );
232- foreach ($ lines as &$ line ) {
236+ foreach ($ lines as &$ line ) {
233237 $ line = preg_replace_callback ('# ( +)|^ # ' , array ($ this , 'fixSpaces ' ), $ line );
234238 }
235239 return $ lines ;
@@ -245,9 +249,9 @@ protected function fixSpaces($matches)
245249 {
246250 $ buffer = '' ;
247251 $ count = 0 ;
248- foreach ($ matches as $ spaces ){
252+ foreach ($ matches as $ spaces ) {
249253 $ count = strlen ($ spaces );
250- if ($ count == 0 ) {
254+ if ($ count == 0 ) {
251255 continue ;
252256 }
253257 $ div = (int ) floor ($ count / 2 );
@@ -269,12 +273,12 @@ protected function fixSpaces($matches)
269273 private function expandTabs ($ line )
270274 {
271275 $ tabSize = $ this ->options ['tabSize ' ];
272- while (($ pos = strpos ($ line , "\t" )) !== FALSE ) {
276+ while (($ pos = strpos ($ line , "\t" )) !== false ) {
273277 $ left = substr ($ line , 0 , $ pos );
274278 $ right = substr ($ line , $ pos + 1 );
275279 $ length = $ tabSize - ($ pos % $ tabSize );
276280 $ spaces = str_repeat (' ' , $ length );
277- $ line = $ left. $ spaces. $ right ;
281+ $ line = $ left . $ spaces . $ right ;
278282 }
279283 return $ line ;
280284 }
@@ -296,8 +300,10 @@ private function htmlSafe($string)
296300 * @param integer $j1
297301 * @return array
298302 */
299- private function getDefaultArray ($ tag , $ i1 , $ j1 ){
300- return array (
303+ private function getDefaultArray ($ tag , $ i1 , $ j1 )
304+ {
305+ return array
306+ (
301307 'tag ' => $ tag ,
302308 'base ' => array (
303309 'offset ' => $ i1 ,
0 commit comments