99 */
1010namespace SebastianBergmann \Diff ;
1111
12+ use const PHP_INT_SIZE ;
13+ use const PREG_SPLIT_DELIM_CAPTURE ;
14+ use const PREG_SPLIT_NO_EMPTY ;
15+ use function array_shift ;
16+ use function array_unshift ;
17+ use function array_values ;
18+ use function count ;
19+ use function current ;
20+ use function end ;
21+ use function get_class ;
22+ use function gettype ;
23+ use function is_array ;
24+ use function is_object ;
25+ use function is_string ;
26+ use function key ;
27+ use function min ;
28+ use function preg_split ;
29+ use function prev ;
30+ use function reset ;
31+ use function sprintf ;
32+ use function substr ;
1233use SebastianBergmann \Diff \Output \DiffOutputBuilderInterface ;
1334use SebastianBergmann \Diff \Output \UnifiedDiffOutputBuilder ;
1435
@@ -40,16 +61,16 @@ public function __construct($outputBuilder = null)
4061 $ this ->outputBuilder = $ outputBuilder ;
4162 } elseif (null === $ outputBuilder ) {
4263 $ this ->outputBuilder = new UnifiedDiffOutputBuilder ;
43- } elseif (\ is_string ($ outputBuilder )) {
64+ } elseif (is_string ($ outputBuilder )) {
4465 // PHPUnit 6.1.4, 6.2.0, 6.2.1, 6.2.2, and 6.2.3 support
4566 // @see https://github.com/sebastianbergmann/phpunit/issues/2734#issuecomment-314514056
4667 // @deprecated
4768 $ this ->outputBuilder = new UnifiedDiffOutputBuilder ($ outputBuilder );
4869 } else {
4970 throw new InvalidArgumentException (
50- \ sprintf (
71+ sprintf (
5172 'Expected builder to be an instance of DiffOutputBuilderInterface, <null> or a string, got %s. ' ,
52- \ is_object ($ outputBuilder ) ? 'instance of " ' . \ get_class ($ outputBuilder ) . '" ' : \ gettype ($ outputBuilder ) . ' " ' . $ outputBuilder . '" '
73+ is_object ($ outputBuilder ) ? 'instance of " ' . get_class ($ outputBuilder ) . '" ' : gettype ($ outputBuilder ) . ' " ' . $ outputBuilder . '" '
5374 )
5475 );
5576 }
@@ -89,15 +110,15 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
89110 */
90111 public function diffToArray ($ from , $ to , LongestCommonSubsequenceCalculator $ lcs = null ): array
91112 {
92- if (\ is_string ($ from )) {
113+ if (is_string ($ from )) {
93114 $ from = $ this ->splitStringByLines ($ from );
94- } elseif (!\ is_array ($ from )) {
115+ } elseif (!is_array ($ from )) {
95116 throw new InvalidArgumentException ('"from" must be an array or string. ' );
96117 }
97118
98- if (\ is_string ($ to )) {
119+ if (is_string ($ to )) {
99120 $ to = $ this ->splitStringByLines ($ to );
100- } elseif (!\ is_array ($ to )) {
121+ } elseif (!is_array ($ to )) {
101122 throw new InvalidArgumentException ('"to" must be an array or string. ' );
102123 }
103124
@@ -107,36 +128,36 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
107128 $ lcs = $ this ->selectLcsImplementation ($ from , $ to );
108129 }
109130
110- $ common = $ lcs ->calculate (\ array_values ($ from ), \ array_values ($ to ));
131+ $ common = $ lcs ->calculate (array_values ($ from ), array_values ($ to ));
111132 $ diff = [];
112133
113134 foreach ($ start as $ token ) {
114135 $ diff [] = [$ token , self ::OLD ];
115136 }
116137
117- \ reset ($ from );
118- \ reset ($ to );
138+ reset ($ from );
139+ reset ($ to );
119140
120141 foreach ($ common as $ token ) {
121- while (($ fromToken = \ reset ($ from )) !== $ token ) {
122- $ diff [] = [\ array_shift ($ from ), self ::REMOVED ];
142+ while (($ fromToken = reset ($ from )) !== $ token ) {
143+ $ diff [] = [array_shift ($ from ), self ::REMOVED ];
123144 }
124145
125- while (($ toToken = \ reset ($ to )) !== $ token ) {
126- $ diff [] = [\ array_shift ($ to ), self ::ADDED ];
146+ while (($ toToken = reset ($ to )) !== $ token ) {
147+ $ diff [] = [array_shift ($ to ), self ::ADDED ];
127148 }
128149
129150 $ diff [] = [$ token , self ::OLD ];
130151
131- \ array_shift ($ from );
132- \ array_shift ($ to );
152+ array_shift ($ from );
153+ array_shift ($ to );
133154 }
134155
135- while (($ token = \ array_shift ($ from )) !== null ) {
156+ while (($ token = array_shift ($ from )) !== null ) {
136157 $ diff [] = [$ token , self ::REMOVED ];
137158 }
138159
139- while (($ token = \ array_shift ($ to )) !== null ) {
160+ while (($ token = array_shift ($ to )) !== null ) {
140161 $ diff [] = [$ token , self ::ADDED ];
141162 }
142163
@@ -145,7 +166,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
145166 }
146167
147168 if ($ this ->detectUnmatchedLineEndings ($ diff )) {
148- \ array_unshift ($ diff , ["#Warning: Strings contain different line endings! \n" , self ::DIFF_LINE_END_WARNING ]);
169+ array_unshift ($ diff , ["#Warning: Strings contain different line endings! \n" , self ::DIFF_LINE_END_WARNING ]);
149170 }
150171
151172 return $ diff ;
@@ -158,7 +179,7 @@ public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs
158179 */
159180 private function normalizeDiffInput ($ input )
160181 {
161- if (!\ is_array ($ input ) && !\ is_string ($ input )) {
182+ if (!is_array ($ input ) && !is_string ($ input )) {
162183 return (string ) $ input ;
163184 }
164185
@@ -170,7 +191,7 @@ private function normalizeDiffInput($input)
170191 */
171192 private function splitStringByLines (string $ input ): array
172193 {
173- return \ preg_split ('/(.*\R)/ ' , $ input , -1 , \ PREG_SPLIT_DELIM_CAPTURE | \ PREG_SPLIT_NO_EMPTY );
194+ return preg_split ('/(.*\R)/ ' , $ input , -1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
174195 }
175196
176197 private function selectLcsImplementation (array $ from , array $ to ): LongestCommonSubsequenceCalculator
@@ -195,9 +216,9 @@ private function selectLcsImplementation(array $from, array $to): LongestCommonS
195216 */
196217 private function calculateEstimatedFootprint (array $ from , array $ to )
197218 {
198- $ itemSize = \ PHP_INT_SIZE === 4 ? 76 : 144 ;
219+ $ itemSize = PHP_INT_SIZE === 4 ? 76 : 144 ;
199220
200- return $ itemSize * \ min (\ count ($ from ), \ count ($ to )) ** 2 ;
221+ return $ itemSize * min (count ($ from ), count ($ to )) ** 2 ;
201222 }
202223
203224 /**
@@ -243,11 +264,11 @@ private function detectUnmatchedLineEndings(array $diff): bool
243264
244265 private function getLinebreak ($ line ): string
245266 {
246- if (!\ is_string ($ line )) {
267+ if (!is_string ($ line )) {
247268 return '' ;
248269 }
249270
250- $ lc = \ substr ($ line , -1 );
271+ $ lc = substr ($ line , -1 );
251272
252273 if ("\r" === $ lc ) {
253274 return "\r" ;
@@ -257,7 +278,7 @@ private function getLinebreak($line): string
257278 return '' ;
258279 }
259280
260- if ("\r\n" === \ substr ($ line , -2 )) {
281+ if ("\r\n" === substr ($ line , -2 )) {
261282 return "\r\n" ;
262283 }
263284
@@ -269,10 +290,10 @@ private static function getArrayDiffParted(array &$from, array &$to): array
269290 $ start = [];
270291 $ end = [];
271292
272- \ reset ($ to );
293+ reset ($ to );
273294
274295 foreach ($ from as $ k => $ v ) {
275- $ toK = \ key ($ to );
296+ $ toK = key ($ to );
276297
277298 if ($ toK === $ k && $ v === $ to [$ k ]) {
278299 $ start [$ k ] = $ v ;
@@ -283,19 +304,19 @@ private static function getArrayDiffParted(array &$from, array &$to): array
283304 }
284305 }
285306
286- \ end ($ from );
287- \ end ($ to );
307+ end ($ from );
308+ end ($ to );
288309
289310 do {
290- $ fromK = \ key ($ from );
291- $ toK = \ key ($ to );
311+ $ fromK = key ($ from );
312+ $ toK = key ($ to );
292313
293- if (null === $ fromK || null === $ toK || \ current ($ from ) !== \ current ($ to )) {
314+ if (null === $ fromK || null === $ toK || current ($ from ) !== current ($ to )) {
294315 break ;
295316 }
296317
297- \ prev ($ from );
298- \ prev ($ to );
318+ prev ($ from );
319+ prev ($ to );
299320
300321 $ end = [$ fromK => $ from [$ fromK ]] + $ end ;
301322 unset($ from [$ fromK ], $ to [$ toK ]);
0 commit comments