Skip to content

Commit db8bd20

Browse files
author
Sven Hagemann
authored
PHP8 Compatibility
PHP8 Compatibility
2 parents d304b3c + 1fbc0ca commit db8bd20

File tree

9 files changed

+88
-81
lines changed

9 files changed

+88
-81
lines changed

.scrutinizer.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ imports:
33
tools:
44
js_hint: true
55
php_code_sniffer: true
6-
php_cs_fixer:
7-
config: { level: psr2 }
8-
enabled: true
6+
97
build:
10-
tests:
11-
override:
12-
-
13-
command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file'
14-
coverage:
15-
file: 'code-coverage-file'
16-
format: 'php-clover'
8+
nodes:
9+
analysis:
10+
tests:
11+
override:
12+
- phpcs-run
13+
tests:
14+
tests:
15+
override:
16+
-
17+
command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file'
18+
coverage:
19+
file: 'code-coverage-file'
20+
format: 'php-clover'
21+
1722
filter:
1823
excluded_paths:
1924
- tests/*
@@ -130,4 +135,4 @@ checks:
130135
no_underscore_prefix_in_properties: true
131136
no_underscore_prefix_in_methods: true
132137
blank_line_after_namespace_declaration: true
133-
verify_argument_usable_as_reference: true
138+
verify_argument_usable_as_reference: true

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"issues": "https://github.com/caxy/php-htmldiff/issues"
2020
},
2121
"require": {
22-
"php": ">=5.3.3",
22+
"php": ">=7.3",
2323
"ezyang/htmlpurifier": "^4.7",
2424
"kub-at/php-simple-html-dom-parser": "^1.7"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "~5.0",
27+
"phpunit/phpunit": "~9.0",
2828
"doctrine/cache": "~1.0"
2929
},
3030
"suggest": {

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.

lib/Caxy/HtmlDiff/MatchingBlock.php

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+
}

phpcs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<file>./lib</file>
4+
<file>./tests</file>
5+
<rule ref="PSR2" />
6+
</ruleset>

phpunit.xml.dist

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
processIsolation="false"
9-
stopOnFailure="false"
10-
syntaxCheck="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
3+
colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
4+
convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"
115
bootstrap="./tests/Caxy/Tests/TestInit.php"
12-
>
13-
14-
<groups>
15-
<exclude>
16-
<group>performance</group>
17-
</exclude>
18-
</groups>
19-
20-
<testsuites>
21-
<testsuite name="php-htmldiff Test Suite">
22-
<directory>./tests/Caxy/Tests/HtmlDiff</directory>
23-
</testsuite>
24-
</testsuites>
25-
26-
<filter>
27-
<whitelist processUncoveredFilesFromWhitelist="true">
28-
<directory suffix=".php">./lib</directory>
29-
</whitelist>
30-
</filter>
31-
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
7+
<coverage processUncoveredFiles="true">
8+
<include>
9+
<directory suffix=".php">./lib</directory>
10+
</include>
11+
</coverage>
12+
<groups>
13+
<exclude>
14+
<group>performance</group>
15+
</exclude>
16+
</groups>
17+
<testsuites>
18+
<testsuite name="php-htmldiff Test Suite">
19+
<directory>./tests/Caxy/Tests/HtmlDiff</directory>
20+
</testsuite>
21+
</testsuites>
3222
</phpunit>

tests/Caxy/Tests/AbstractTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Caxy\Tests;
44

5-
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
5+
use PHPUnit\Framework\TestCase;
6+
7+
abstract class AbstractTest extends TestCase
68
{
79
protected function stripExtraWhitespaceAndNewLines($text)
810
{
@@ -14,4 +16,4 @@ protected function stripExtraWhitespaceAndNewLines($text)
1416
)
1517
);
1618
}
17-
}
19+
}

tests/Caxy/Tests/HtmlDiff/Functional/HTMLPurifierConfigTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class HTMLPurifierConfigTest extends AbstractTest
1313
*/
1414
protected $config;
1515

16-
public function setUp()
16+
public function setUp() : void
1717
{
1818
$config = \HTMLPurifier_Config::createDefault();
1919

@@ -73,4 +73,4 @@ public function testHtmlDiffConfigStatic()
7373
$diff->setHTMLPurifierConfig($this->config);
7474
$diff->build();
7575
}
76-
}
76+
}

0 commit comments

Comments
 (0)