Skip to content

Commit 7a7a967

Browse files
author
Sven Hagemann
committed
Fix PHP8 classname incompatibility (Match)
Match is a keyword in PHP8 that is used to do RegExp operations. This causes htmldiff to not function on PHP8 since one its classnames (Match) collides with the new keyword. I renamed it to MatchingBlock, this is less ambigous, and fixes the PHP incompatibility in the process.
1 parent 4fe069f commit 7a7a967

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

lib/Caxy/HtmlDiff/HtmlDiff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ protected function operations()
696696
$operations = array();
697697

698698
$matches = $this->matchingBlocks();
699-
$matches[] = new Match(count($this->oldWords), count($this->newWords), 0);
699+
$matches[] = new MatchingBlock(count($this->oldWords), count($this->newWords), 0);
700700

701701
foreach ($matches as $match) {
702702
$matchStartsAtCurrentPositionInOld = ($positionInOld === $match->startInOld);
@@ -728,7 +728,7 @@ protected function operations()
728728
}
729729

730730
/**
731-
* @return Match[]
731+
* @return MatchingBlock[]
732732
*/
733733
protected function matchingBlocks()
734734
{
@@ -784,7 +784,7 @@ protected function stripTagAttributes($word)
784784
* @param int $startInNew
785785
* @param int $endInNew
786786
*
787-
* @return Match|null
787+
* @return MatchingBlock|null
788788
*/
789789
protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
790790
{
@@ -837,7 +837,7 @@ protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
837837
!$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
838838
)
839839
) {
840-
return new Match($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
840+
return new MatchingBlock($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
841841
}
842842

843843
return null;

lib/Caxy/HtmlDiff/Match.php

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Caxy\HtmlDiff;
4+
5+
/**
6+
* A (string) block of text is the same between the two provided versions.
7+
*/
8+
class MatchingBlock implements \Countable
9+
{
10+
public $startInOld;
11+
public $startInNew;
12+
public $size;
13+
14+
public function __construct(int $startInOld, int $startInNew, int $size)
15+
{
16+
$this->startInOld = $startInOld;
17+
$this->startInNew = $startInNew;
18+
$this->size = $size;
19+
}
20+
21+
public function endInOld() : int
22+
{
23+
return ($this->startInOld + $this->size);
24+
}
25+
26+
public function endInNew() : int
27+
{
28+
return ($this->startInNew + $this->size);
29+
}
30+
31+
public function count() : int
32+
{
33+
return (int)$this->size;
34+
}
35+
}

0 commit comments

Comments
 (0)