1010
1111namespace SebastianBergmann \Diff ;
1212
13- use SebastianBergmann \Diff \LongestCommonSubsequenceCalculator ;
14- use SebastianBergmann \Diff \TimeEfficientLongestCommonSubsequenceCalculator ;
15- use SebastianBergmann \Diff \MemoryEfficientLongestCommonSubsequenceCalculator ;
16-
1713/**
1814 * Diff implementation.
1915 */
@@ -42,8 +38,8 @@ public function __construct($header = "--- Original\n+++ New\n", $showNonDiffLin
4238 /**
4339 * Returns the diff between two arrays or strings as string.
4440 *
45- * @param array|string $from
46- * @param array|string $to
41+ * @param array|string $from
42+ * @param array|string $to
4743 * @param LongestCommonSubsequenceCalculator $lcs
4844 *
4945 * @return string
@@ -92,7 +88,7 @@ private function checkIfDiffInOld(array $diff)
9288 {
9389 $ inOld = false ;
9490 $ i = 0 ;
95- $ old = array () ;
91+ $ old = [] ;
9692
9793 foreach ($ diff as $ line ) {
9894 if ($ line [1 ] === 0 /* OLD */ ) {
@@ -195,8 +191,8 @@ private function getDiffBufferElementNew(array $diff, $buffer, $diffIndex)
195191 * - 1: ADDED: $token was added to $from
196192 * - 0: OLD: $token is not changed in $to
197193 *
198- * @param array|string $from
199- * @param array|string $to
194+ * @param array|string $from
195+ * @param array|string $to
200196 * @param LongestCommonSubsequenceCalculator $lcs
201197 *
202198 * @return array
@@ -207,7 +203,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
207203 $ fromMatches = $ this ->getNewLineMatches ($ from );
208204 $ from = $ this ->splitStringByLines ($ from );
209205 } elseif (\is_array ($ from )) {
210- $ fromMatches = array () ;
206+ $ fromMatches = [] ;
211207 } else {
212208 throw new \InvalidArgumentException ('"from" must be an array or string. ' );
213209 }
@@ -216,7 +212,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
216212 $ toMatches = $ this ->getNewLineMatches ($ to );
217213 $ to = $ this ->splitStringByLines ($ to );
218214 } elseif (\is_array ($ to )) {
219- $ toMatches = array () ;
215+ $ toMatches = [] ;
220216 } else {
221217 throw new \InvalidArgumentException ('"to" must be an array or string. ' );
222218 }
@@ -228,47 +224,47 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
228224 }
229225
230226 $ common = $ lcs ->calculate (\array_values ($ from ), \array_values ($ to ));
231- $ diff = array () ;
227+ $ diff = [] ;
232228
233229 if ($ this ->detectUnmatchedLineEndings ($ fromMatches , $ toMatches )) {
234- $ diff [] = array (
230+ $ diff [] = [
235231 '#Warning: Strings contain different line endings! ' ,
236232 0
237- ) ;
233+ ] ;
238234 }
239235
240236 foreach ($ start as $ token ) {
241- $ diff [] = array ( $ token , 0 /* OLD */ ) ;
237+ $ diff [] = [ $ token , 0 /* OLD */ ] ;
242238 }
243239
244240 \reset ($ from );
245241 \reset ($ to );
246242
247243 foreach ($ common as $ token ) {
248244 while (($ fromToken = \reset ($ from )) !== $ token ) {
249- $ diff [] = array ( \array_shift ($ from ), 2 /* REMOVED */ ) ;
245+ $ diff [] = [ \array_shift ($ from ), 2 /* REMOVED */ ] ;
250246 }
251247
252248 while (($ toToken = \reset ($ to )) !== $ token ) {
253- $ diff [] = array ( \array_shift ($ to ), 1 /* ADDED */ ) ;
249+ $ diff [] = [ \array_shift ($ to ), 1 /* ADDED */ ] ;
254250 }
255251
256- $ diff [] = array ( $ token , 0 /* OLD */ ) ;
252+ $ diff [] = [ $ token , 0 /* OLD */ ] ;
257253
258254 \array_shift ($ from );
259255 \array_shift ($ to );
260256 }
261257
262258 while (($ token = \array_shift ($ from )) !== null ) {
263- $ diff [] = array ( $ token , 2 /* REMOVED */ ) ;
259+ $ diff [] = [ $ token , 2 /* REMOVED */ ] ;
264260 }
265261
266262 while (($ token = \array_shift ($ to )) !== null ) {
267- $ diff [] = array ( $ token , 1 /* ADDED */ ) ;
263+ $ diff [] = [ $ token , 1 /* ADDED */ ] ;
268264 }
269265
270266 foreach ($ end as $ token ) {
271- $ diff [] = array ( $ token , 0 /* OLD */ ) ;
267+ $ diff [] = [ $ token , 0 /* OLD */ ] ;
272268 }
273269
274270 return $ diff ;
@@ -359,8 +355,8 @@ private function detectUnmatchedLineEndings(array $fromMatches, array $toMatches
359355 */
360356 private static function getArrayDiffParted (array &$ from , array &$ to )
361357 {
362- $ start = array () ;
363- $ end = array () ;
358+ $ start = [] ;
359+ $ end = [] ;
364360
365361 \reset ($ to );
366362
@@ -390,10 +386,10 @@ private static function getArrayDiffParted(array &$from, array &$to)
390386 \prev ($ from );
391387 \prev ($ to );
392388
393- $ end = array ( $ fromK => $ from [$ fromK ]) + $ end ;
389+ $ end = [ $ fromK => $ from [$ fromK ]] + $ end ;
394390 unset($ from [$ fromK ], $ to [$ toK ]);
395391 } while (true );
396392
397- return array ( $ from , $ to , $ start , $ end) ;
393+ return [ $ from , $ to , $ start , $ end] ;
398394 }
399395}
0 commit comments