@@ -65,13 +65,13 @@ class SequenceMatcher
65
65
/**
66
66
* @var array
67
67
*/
68
- private $ defaultOptions = array (
68
+ private $ defaultOptions = [
69
69
'context ' => 3 ,
70
70
'trimEqual ' => true ,
71
71
'ignoreWhitespace ' => false ,
72
72
'ignoreCase ' => false ,
73
73
'ignoreNewLines ' => false ,
74
- ) ;
74
+ ] ;
75
75
76
76
/**
77
77
* The constructor. With the sequences being passed, they'll be set for the
@@ -86,8 +86,8 @@ class SequenceMatcher
86
86
*/
87
87
public function __construct ($ old , $ new , array $ options = [], $ junkCallback = null )
88
88
{
89
- $ this ->old = array () ;
90
- $ this ->new = array () ;
89
+ $ this ->old = [] ;
90
+ $ this ->new = [] ;
91
91
$ this ->junkCallback = $ junkCallback ;
92
92
$ this ->setOptions ($ options );
93
93
$ this ->setSequences ($ old , $ new );
@@ -164,8 +164,8 @@ public function setSeq2($partB)
164
164
private function chainB ()
165
165
{
166
166
$ length = count ($ this ->new );
167
- $ this ->b2j = array () ;
168
- $ popularDict = array () ;
167
+ $ this ->b2j = [] ;
168
+ $ popularDict = [] ;
169
169
170
170
for ($ i = 0 ; $ i < $ length ; ++$ i ) {
171
171
$ char = $ this ->new [$ i ];
@@ -177,9 +177,9 @@ private function chainB()
177
177
$ this ->b2j [$ char ][] = $ i ;
178
178
}
179
179
} else {
180
- $ this ->b2j [$ char ] = array (
180
+ $ this ->b2j [$ char ] = [
181
181
$ i
182
- ) ;
182
+ ] ;
183
183
}
184
184
}
185
185
@@ -188,7 +188,7 @@ private function chainB()
188
188
unset($ this ->b2j [$ char ]);
189
189
}
190
190
191
- $ this ->junkDict = array () ;
191
+ $ this ->junkDict = [] ;
192
192
if (is_callable ($ this ->junkCallback )) {
193
193
foreach (array_keys ($ popularDict ) as $ char ) {
194
194
if (call_user_func ($ this ->junkCallback , $ char )) {
@@ -251,11 +251,11 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
251
251
$ bestJ = $ blo ;
252
252
$ bestSize = 0 ;
253
253
254
- $ j2Len = array () ;
255
- $ nothing = array () ;
254
+ $ j2Len = [] ;
255
+ $ nothing = [] ;
256
256
257
257
for ($ i = $ alo ; $ i < $ ahi ; ++$ i ) {
258
- $ newJ2Len = array () ;
258
+ $ newJ2Len = [] ;
259
259
$ jDict = $ this ->arrayGetDefault ($ this ->b2j , $ old [$ i ], $ nothing );
260
260
foreach ($ jDict as $ j ) {
261
261
if ($ j < $ blo ) {
@@ -316,11 +316,11 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
316
316
++$ bestSize ;
317
317
}
318
318
319
- return array (
319
+ return [
320
320
$ bestI ,
321
321
$ bestJ ,
322
322
$ bestSize
323
- ) ;
323
+ ] ;
324
324
}
325
325
326
326
/**
@@ -336,7 +336,7 @@ public function linesAreDifferent(int $aIndex, int $bIndex): bool
336
336
$ lineB = $ this ->new [$ bIndex ];
337
337
338
338
if ($ this ->options ['ignoreWhitespace ' ]) {
339
- $ replace = array ( "\t" , ' ' ) ;
339
+ $ replace = [ "\t" , ' ' ] ;
340
340
$ lineA = str_replace ($ replace , '' , $ lineA );
341
341
$ lineB = str_replace ($ replace , '' , $ lineB );
342
342
}
@@ -372,38 +372,38 @@ public function getMatchingBlocks(): array
372
372
$ aLength = count ($ this ->old );
373
373
$ bLength = count ($ this ->new );
374
374
375
- $ queue = array (
376
- array (
375
+ $ queue = [
376
+ [
377
377
0 ,
378
378
$ aLength ,
379
379
0 ,
380
380
$ bLength
381
- )
382
- ) ;
381
+ ]
382
+ ] ;
383
383
384
- $ matchingBlocks = array () ;
384
+ $ matchingBlocks = [] ;
385
385
while (!empty ($ queue )) {
386
386
[$ alo , $ ahi , $ blo , $ bhi ] = array_pop ($ queue );
387
387
$ longestMatch = $ this ->findLongestMatch ($ alo , $ ahi , $ blo , $ bhi );
388
388
[$ list1 , $ list2 , $ list3 ] = $ longestMatch ;
389
389
if ($ list3 ) {
390
390
$ matchingBlocks [] = $ longestMatch ;
391
391
if ($ alo < $ list1 && $ blo < $ list2 ) {
392
- $ queue [] = array (
392
+ $ queue [] = [
393
393
$ alo ,
394
394
$ list1 ,
395
395
$ blo ,
396
396
$ list2
397
- ) ;
397
+ ] ;
398
398
}
399
399
400
400
if ($ list1 + $ list3 < $ ahi && $ list2 + $ list3 < $ bhi ) {
401
- $ queue [] = array (
401
+ $ queue [] = [
402
402
$ list1 + $ list3 ,
403
403
$ ahi ,
404
404
$ list2 + $ list3 ,
405
405
$ bhi
406
- ) ;
406
+ ] ;
407
407
}
408
408
}
409
409
}
@@ -418,17 +418,17 @@ function ($aArray, $bArray) {
418
418
$ i1 = 0 ;
419
419
$ j1 = 0 ;
420
420
$ k1 = 0 ;
421
- $ nonAdjacent = array () ;
421
+ $ nonAdjacent = [] ;
422
422
foreach ($ matchingBlocks as [$ list4 , $ list5 , $ list6 ]) {
423
423
if ($ i1 + $ k1 == $ list4 && $ j1 + $ k1 == $ list5 ) {
424
424
$ k1 += $ list6 ;
425
425
} else {
426
426
if ($ k1 ) {
427
- $ nonAdjacent [] = array (
427
+ $ nonAdjacent [] = [
428
428
$ i1 ,
429
429
$ j1 ,
430
430
$ k1
431
- ) ;
431
+ ] ;
432
432
}
433
433
434
434
$ i1 = $ list4 ;
@@ -438,18 +438,18 @@ function ($aArray, $bArray) {
438
438
}
439
439
440
440
if ($ k1 ) {
441
- $ nonAdjacent [] = array (
441
+ $ nonAdjacent [] = [
442
442
$ i1 ,
443
443
$ j1 ,
444
444
$ k1
445
- ) ;
445
+ ] ;
446
446
}
447
447
448
- $ nonAdjacent [] = array (
448
+ $ nonAdjacent [] = [
449
449
$ aLength ,
450
450
$ bLength ,
451
451
0
452
- ) ;
452
+ ] ;
453
453
454
454
$ this ->matchingBlocks = $ nonAdjacent ;
455
455
return $ this ->matchingBlocks ;
@@ -485,7 +485,7 @@ public function getOpCodes(): array
485
485
486
486
$ i = 0 ;
487
487
$ j = 0 ;
488
- $ this ->opCodes = array () ;
488
+ $ this ->opCodes = [] ;
489
489
490
490
$ blocks = $ this ->getMatchingBlocks ();
491
491
foreach ($ blocks as [$ ai , $ bj , $ size ]) {
@@ -499,26 +499,26 @@ public function getOpCodes(): array
499
499
}
500
500
501
501
if ($ tag ) {
502
- $ this ->opCodes [] = array (
502
+ $ this ->opCodes [] = [
503
503
$ tag ,
504
504
$ i ,
505
505
$ ai ,
506
506
$ j ,
507
507
$ bj
508
- ) ;
508
+ ] ;
509
509
}
510
510
511
511
$ i = $ ai + $ size ;
512
512
$ j = $ bj + $ size ;
513
513
514
514
if ($ size ) {
515
- $ this ->opCodes [] = array (
515
+ $ this ->opCodes [] = [
516
516
'equal ' ,
517
517
$ ai ,
518
518
$ i ,
519
519
$ bj ,
520
520
$ j
521
- ) ;
521
+ ] ;
522
522
}
523
523
}
524
524
return $ this ->opCodes ;
@@ -541,69 +541,69 @@ public function getGroupedOpCodes(): array
541
541
{
542
542
$ opCodes = $ this ->getOpCodes ();
543
543
if (empty ($ opCodes )) {
544
- $ opCodes = array (
545
- array (
544
+ $ opCodes = [
545
+ [
546
546
'equal ' ,
547
547
0 ,
548
548
1 ,
549
549
0 ,
550
550
1
551
- )
552
- ) ;
551
+ ]
552
+ ] ;
553
553
}
554
554
555
555
if ($ this ->options ['trimEqual ' ]) {
556
556
if ($ opCodes ['0 ' ]['0 ' ] == 'equal ' ) {
557
557
// Remove sequences at the start which are out of context.
558
- $ opCodes ['0 ' ] = array (
558
+ $ opCodes ['0 ' ] = [
559
559
$ opCodes ['0 ' ]['0 ' ],
560
560
max ($ opCodes ['0 ' ]['1 ' ], $ opCodes ['0 ' ]['2 ' ] - $ this ->options ['context ' ]),
561
561
$ opCodes ['0 ' ]['2 ' ],
562
562
max ($ opCodes ['0 ' ]['3 ' ], $ opCodes ['0 ' ]['4 ' ] - $ this ->options ['context ' ]),
563
563
$ opCodes ['0 ' ]['4 ' ]
564
- ) ;
564
+ ] ;
565
565
}
566
566
567
567
$ lastItem = count ($ opCodes ) - 1 ;
568
568
if ($ opCodes [$ lastItem ]['0 ' ] == 'equal ' ) {
569
569
[$ tag , $ i1 , $ i2 , $ j1 , $ j2 ] = $ opCodes [$ lastItem ];
570
570
// Remove sequences at the end which are out of context.
571
- $ opCodes [$ lastItem ] = array (
571
+ $ opCodes [$ lastItem ] = [
572
572
$ tag ,
573
573
$ i1 ,
574
574
min ($ i2 , $ i1 + $ this ->options ['context ' ]),
575
575
$ j1 ,
576
576
min ($ j2 , $ j1 + $ this ->options ['context ' ])
577
- ) ;
577
+ ] ;
578
578
}
579
579
}
580
580
581
581
$ maxRange = $ this ->options ['context ' ] * 2 ;
582
- $ groups = array () ;
583
- $ group = array () ;
582
+ $ groups = [] ;
583
+ $ group = [] ;
584
584
585
585
foreach ($ opCodes as [$ tag , $ i1 , $ i2 , $ j1 , $ j2 ]) {
586
586
if ($ tag == 'equal ' && $ i2 - $ i1 > $ maxRange ) {
587
- $ group [] = array (
587
+ $ group [] = [
588
588
$ tag ,
589
589
$ i1 ,
590
590
min ($ i2 , $ i1 + $ this ->options ['context ' ]),
591
591
$ j1 ,
592
592
min ($ j2 , $ j1 + $ this ->options ['context ' ])
593
- ) ;
593
+ ] ;
594
594
$ groups [] = $ group ;
595
- $ group = array () ;
595
+ $ group = [] ;
596
596
$ i1 = max ($ i1 , $ i2 - $ this ->options ['context ' ]);
597
597
$ j1 = max ($ j1 , $ j2 - $ this ->options ['context ' ]);
598
598
}
599
599
600
- $ group [] = array (
600
+ $ group [] = [
601
601
$ tag ,
602
602
$ i1 ,
603
603
$ i2 ,
604
604
$ j1 ,
605
605
$ j2
606
- ) ;
606
+ ] ;
607
607
}
608
608
609
609
if ($ this ->options ['trimEqual ' ] || (!empty ($ group ) && !(count ($ group ) == 1 && $ group [0 ][0 ] == 'equal ' ))) {
0 commit comments