Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 4e0c886

Browse files
Drop support for PHP 5
1 parent 22ef7d6 commit 4e0c886

15 files changed

+228
-238
lines changed

.php_cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ return PhpCsFixer\Config::create()
1212
->setRiskyAllowed(true)
1313
->setRules(
1414
[
15-
'array_syntax' => ['syntax' => 'long'],
15+
'array_syntax' => ['syntax' => 'short'],
1616
'binary_operator_spaces' => [
1717
'align_double_arrow' => true,
1818
'align_equals' => true

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3
5-
- 5.4
6-
- 5.5
7-
- 5.6
84
- 7.0
95
- 7.0snapshot
106
- 7.1

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^5.3.3 || ^7.0"
18+
"php": "^7.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
21+
"phpunit/phpunit": "^6.1"
2222
},
2323
"autoload": {
2424
"classmap": [
@@ -27,7 +27,7 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.4-dev"
30+
"dev-master": "2.0-dev"
3131
}
3232
}
3333
}

src/Chunk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Chunk
4444
* @param int $endRange
4545
* @param array $lines
4646
*/
47-
public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = array())
47+
public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
4848
{
4949
$this->start = (int) $start;
5050
$this->startRange = (int) $startRange;

src/Diff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Diff
3232
* @param string $to
3333
* @param Chunk[] $chunks
3434
*/
35-
public function __construct($from, $to, array $chunks = array())
35+
public function __construct($from, $to, array $chunks = [])
3636
{
3737
$this->from = $from;
3838
$this->to = $to;

src/Differ.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
namespace 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
}

src/MemoryEfficientLongestCommonSubsequenceCalculator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public function calculate(array $from, array $to)
2626
$cTo = \count($to);
2727

2828
if ($cFrom === 0) {
29-
return array();
29+
return [];
3030
}
3131

3232
if ($cFrom === 1) {
3333
if (\in_array($from[0], $to, true)) {
34-
return array($from[0]);
34+
return [$from[0]];
3535
}
3636

37-
return array();
37+
return [];
3838
}
3939

4040
$i = (int) ($cFrom / 2);

src/Parser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function parse($string)
2929
}
3030

3131
$lineCount = \count($lines);
32-
$diffs = array();
32+
$diffs = [];
3333
$diff = null;
34-
$collected = array();
34+
$collected = [];
3535

3636
for ($i = 0; $i < $lineCount; ++$i) {
3737
if (\preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) &&
@@ -40,7 +40,7 @@ public function parse($string)
4040
$this->parseFileDiff($diff, $collected);
4141

4242
$diffs[] = $diff;
43-
$collected = array();
43+
$collected = [];
4444
}
4545

4646
$diff = new Diff($fromMatch['file'], $toMatch['file']);
@@ -70,7 +70,7 @@ public function parse($string)
7070
*/
7171
private function parseFileDiff(Diff $diff, array $lines)
7272
{
73-
$chunks = array();
73+
$chunks = [];
7474
$chunk = null;
7575

7676
foreach ($lines as $line) {
@@ -83,7 +83,7 @@ private function parseFileDiff(Diff $diff, array $lines)
8383
);
8484

8585
$chunks[] = $chunk;
86-
$diffLines = array();
86+
$diffLines = [];
8787

8888
continue;
8989
}

src/TimeEfficientLongestCommonSubsequenceCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSu
2222
*/
2323
public function calculate(array $from, array $to)
2424
{
25-
$common = array();
25+
$common = [];
2626
$fromLength = \count($from);
2727
$toLength = \count($to);
2828
$width = $fromLength + 1;

tests/ChunkTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function setUp()
2929

3030
public function testCanBeCreatedWithoutArguments()
3131
{
32-
$this->assertInstanceOf('SebastianBergmann\Diff\Chunk', $this->chunk);
32+
$this->assertInstanceOf(Chunk::class, $this->chunk);
3333
}
3434

3535
public function testStartCanBeRetrieved()
@@ -54,14 +54,14 @@ public function testEndRangeCanBeRetrieved()
5454

5555
public function testLinesCanBeRetrieved()
5656
{
57-
$this->assertEquals(array(), $this->chunk->getLines());
57+
$this->assertEquals([], $this->chunk->getLines());
5858
}
5959

6060
public function testLinesCanBeSet()
6161
{
62-
$this->assertEquals(array(), $this->chunk->getLines());
62+
$this->assertEquals([], $this->chunk->getLines());
6363

64-
$testValue = array('line0', 'line1');
64+
$testValue = ['line0', 'line1'];
6565
$this->chunk->setLines($testValue);
6666
$this->assertEquals($testValue, $this->chunk->getLines());
6767
}

0 commit comments

Comments
 (0)