Skip to content

Commit e93beb9

Browse files
Merge pull request #18 from ErnestStaug/php-8-update
Add support of PHP 8.0
2 parents 44d2167 + 2e0547a commit e93beb9

16 files changed

Lines changed: 66 additions & 131 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Thumbs.db
2424
# Stub for empty folders #
2525
##########################
2626
!.gitkeep
27+
.phpunit.result.cache

.travis.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
6-
- 7.1
7-
- 7.2
84
- 7.3
95
- 7.4
6+
- 8.0
107

118
install:
129
- composer install
13-
14-
matrix:
15-
include:
16-
- php: 5.3
17-
dist: precise
18-
- php: 5.4
19-
dist: trusty
20-
- php: 5.5
21-
dist: trusty
22-
allow_failures:
23-
- php: 5.3

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ CMD [ "/bin/bash" ]
1616
# export PHP_VERSION=7.2
1717
# docker build -t dmp:${PHP_VERSION} --build-arg PHP_VERSION=${PHP_VERSION} .
1818
# docker run -it --rm dmp:${PHP_VERSION} ./vendor/bin/phpunit
19-
# docker run -it --rm -v `pwd`:/usr/src/myapp dmp:${PHP_VERSION}
19+
# docker run -it --rm -v `pwd`/src:/app/src -v `pwd`/tests:/app/tests dmp:${PHP_VERSION}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ of a flexible [matching and patching strategy](http://neil.fraser.name/writing/p
144144

145145
## Requirements
146146

147-
* PHP 5.3+
147+
* PHP 7.3+
148148
* [Composer](http://getcomposer.org/)
149149

150150
## License

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=5.3, <8.0",
20+
"php": ">=7.3",
2121
"ext-iconv": "*",
2222
"ext-json": "*",
2323
"ext-mbstring": "*"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "4.*"
26+
"phpunit/phpunit": "9.*"
2727
},
2828
"autoload": {
2929
"psr-4": {

src/DiffMatchPatch.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class DiffMatchPatch
6666
*/
6767
protected $diff;
6868
/**
69-
* @var Match
69+
* @var Matcher
7070
*/
71-
protected $match;
71+
protected $matcher;
7272
/**
7373
* @var Patch
7474
*/
@@ -92,13 +92,13 @@ public function __get($name)
9292
$result = $this->diff->getEditCost();
9393
break;
9494
case 'Match_Threshold':
95-
$result = $this->match->getThreshold();
95+
$result = $this->matcher->getThreshold();
9696
break;
9797
case 'Match_Distance':
98-
$result = $this->match->getDistance();
98+
$result = $this->matcher->getDistance();
9999
break;
100100
case 'Match_MaxBits':
101-
$result = $this->match->getMaxBits();
101+
$result = $this->matcher->getMaxBits();
102102
break;
103103
case 'Patch_DeleteThreshold':
104104
$result = $this->patch->getDeleteTreshold();
@@ -132,13 +132,13 @@ public function __set($name, $value)
132132
$this->diff->setEditCost($value);
133133
break;
134134
case 'Match_Threshold':
135-
$this->match->setThreshold($value);
135+
$this->matcher->setThreshold($value);
136136
break;
137137
case 'Match_Distance':
138-
$this->match->setDistance($value);
138+
$this->matcher->setDistance($value);
139139
break;
140140
case 'Match_MaxBits':
141-
$this->match->setMaxBits($value);
141+
$this->matcher->setMaxBits($value);
142142
break;
143143
case 'Patch_DeleteThreshold':
144144
$this->patch->setDeleteTreshold($value);
@@ -154,8 +154,8 @@ public function __set($name, $value)
154154
public function __construct()
155155
{
156156
$this->diff = new Diff();
157-
$this->match = new Match();
158-
$this->patch = new Patch($this->diff, $this->match);
157+
$this->matcher = new Matcher();
158+
$this->patch = new Patch($this->diff, $this->matcher);
159159
}
160160

161161
/**
@@ -240,7 +240,7 @@ public function diff_prettyHtml($diffs)
240240
*/
241241
public function match_main($text, $pattern, $loc = 0)
242242
{
243-
return $this->match->main($text, $pattern, $loc);
243+
return $this->matcher->main($text, $pattern, $loc);
244244
}
245245

246246
/**

src/Match.php renamed to src/Matcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Neil Fraser <fraser@google.com>
2929
* @author Daniil Skrobov <yetanotherape@gmail.com>
3030
*/
31-
class Match {
31+
class Matcher {
3232

3333
/**
3434
* @var float At what point is no match declared (0.0 = perfection, 1.0 = very loose).

src/Patch.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ class Patch
4646
*/
4747
protected $diff;
4848
/**
49-
* @var Match
49+
* @var Matcher
5050
*/
51-
protected $match;
51+
protected $matcher;
5252

5353
/**
5454
* @param Diff|null $diff
55-
* @param Match|null $match
55+
* @param Matcher|null $matcher
5656
*/
57-
public function __construct(Diff $diff = null, Match $match = null)
57+
public function __construct(Diff $diff = null, Matcher $matcher = null)
5858
{
59-
if (!isset($match)) {
60-
$match = new Match();
59+
if (!isset($matcher)) {
60+
$matcher = new Matcher();
6161
}
6262
if (!isset($diff)) {
6363
$diff = new Diff();
6464
}
6565

6666
$this->diff = $diff;
67-
$this->match = $match;
67+
$this->matcher = $matcher;
6868
}
6969

7070
/**
@@ -100,11 +100,11 @@ public function setMargin($margin)
100100
}
101101

102102
/**
103-
* @return Match
103+
* @return Matcher
104104
*/
105-
protected function getMatch()
105+
protected function getMatcher()
106106
{
107-
return $this->match;
107+
return $this->matcher;
108108
}
109109

110110
/**
@@ -233,10 +233,10 @@ public function addContext(PatchObject $patch, $text)
233233

234234
// Look for the first and last matches of pattern in text.
235235
// If two different matches are found, increase the pattern length.
236-
$match = $this->getMatch();
236+
$matcher = $this->getMatcher();
237237
while (
238238
(!$pattern || mb_strpos($text, $pattern) !== mb_strrpos($text, $pattern)) &&
239-
($match->getMaxBits() == 0 || mb_strlen($pattern) < $match->getMaxBits() - 2 * $this->getMargin())
239+
($matcher->getMaxBits() == 0 || mb_strlen($pattern) < $matcher->getMaxBits() - 2 * $this->getMargin())
240240
) {
241241
$padding += $this->getMargin();
242242
$pattern = mb_substr(
@@ -409,7 +409,7 @@ public function make($a, $b = null, $c = null)
409409
*/
410410
public function splitMax(&$patches)
411411
{
412-
$patchSize = $this->getMatch()->getMaxBits();
412+
$patchSize = $this->getMatcher()->getMaxBits();
413413
if ($patchSize == 0) {
414414
// TODO PHP has fixed size int, so this case isn't relevant.
415415
return;
@@ -619,8 +619,8 @@ public function apply($patches, $text)
619619
$delta = 0;
620620
$results = array();
621621
$diff = $this->getDiff();
622-
$match = $this->getMatch();
623-
$maxBits = $match->getMaxBits();
622+
$matcher = $this->getMatcher();
623+
$maxBits = $matcher->getMaxBits();
624624

625625
foreach ($patches as $patch) {
626626
$expectedLoc = $patch->getStart2() + $delta;
@@ -632,18 +632,18 @@ public function apply($patches, $text)
632632
if ($text1Len > $maxBits) {
633633
// self::splitMax() will only provide an oversized pattern in the case of
634634
// a monster delete.
635-
$startLoc = $match->main($text, mb_substr($text1, 0, $maxBits), $expectedLoc);
635+
$startLoc = $matcher->main($text, mb_substr($text1, 0, $maxBits), $expectedLoc);
636636

637637
if ($startLoc != -1) {
638-
$endLoc = $match->main($text, mb_substr($text1, -$maxBits),
638+
$endLoc = $matcher->main($text, mb_substr($text1, -$maxBits),
639639
$expectedLoc + $text1Len - $maxBits);
640640
if ($endLoc == -1 || $startLoc >= $endLoc) {
641641
// Can't find valid trailing context. Drop this patch.
642642
$startLoc = -1;
643643
}
644644
}
645645
} else {
646-
$startLoc = $match->main($text, $text1, $expectedLoc);
646+
$startLoc = $matcher->main($text, $text1, $expectedLoc);
647647
}
648648

649649
if ($startLoc == -1) {

tests/DiffMatchPatchTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace DiffMatchPatch;
2323

24+
use PHPUnit\Framework\TestCase;
25+
2426
/**
2527
* DiffMatchPatchTest tests that all methods successfully proxies.
2628
* DiffTest, MatchTest and PatchTest contains all other unit tests.
@@ -29,14 +31,14 @@
2931
* @author Neil Fraser <fraser@google.com>
3032
* @author Daniil Skrobov <yetanotherape@gmail.com>
3133
*/
32-
class DiffMatchPatchTest extends \PHPUnit_Framework_TestCase
34+
class DiffMatchPatchTest extends TestCase
3335
{
3436
/**
3537
* @var DiffMatchPatch
3638
*/
3739
protected $dmp;
3840

39-
protected function setUp() {
41+
protected function setUp():void {
4042
mb_internal_encoding('UTF-8');
4143

4244
$this->dmp = new DiffMatchPatch();

tests/DiffTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121

2222
namespace DiffMatchPatch;
2323

24+
use PHPUnit\Framework\TestCase;
25+
2426
/**
2527
* @package DiffMatchPatch
2628
* @author Neil Fraser <fraser@google.com>
2729
* @author Daniil Skrobov <yetanotherape@gmail.com>
2830
*/
29-
class DiffTest extends \PHPUnit_Framework_TestCase
31+
class DiffTest extends TestCase
3032
{
3133
/**
3234
* @var Diff
3335
*/
3436
protected $d;
3537

36-
protected function setUp() {
38+
protected function setUp(): void {
3739
mb_internal_encoding('UTF-8');
3840

3941
$this->d = new Diff();

0 commit comments

Comments
 (0)