Skip to content

Commit

Permalink
PHP8 Compatibility
Browse files Browse the repository at this point in the history
PHP8 Compatibility
  • Loading branch information
Sven Hagemann authored Jan 5, 2021
2 parents d304b3c + 1fbc0ca commit db8bd20
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 81 deletions.
27 changes: 16 additions & 11 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ imports:
tools:
js_hint: true
php_code_sniffer: true
php_cs_fixer:
config: { level: psr2 }
enabled: true

build:
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file'
coverage:
file: 'code-coverage-file'
format: 'php-clover'
nodes:
analysis:
tests:
override:
- phpcs-run
tests:
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=code-coverage-file'
coverage:
file: 'code-coverage-file'
format: 'php-clover'

filter:
excluded_paths:
- tests/*
Expand Down Expand Up @@ -130,4 +135,4 @@ checks:
no_underscore_prefix_in_properties: true
no_underscore_prefix_in_methods: true
blank_line_after_namespace_declaration: true
verify_argument_usable_as_reference: true
verify_argument_usable_as_reference: true
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"issues": "https://github.com/caxy/php-htmldiff/issues"
},
"require": {
"php": ">=5.3.3",
"php": ">=7.3",
"ezyang/htmlpurifier": "^4.7",
"kub-at/php-simple-html-dom-parser": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"phpunit/phpunit": "~9.0",
"doctrine/cache": "~1.0"
},
"suggest": {
Expand Down
8 changes: 4 additions & 4 deletions lib/Caxy/HtmlDiff/HtmlDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ protected function operations()
$operations = array();

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

foreach ($matches as $match) {
$matchStartsAtCurrentPositionInOld = ($positionInOld === $match->startInOld);
Expand Down Expand Up @@ -728,7 +728,7 @@ protected function operations()
}

/**
* @return Match[]
* @return MatchingBlock[]
*/
protected function matchingBlocks()
{
Expand Down Expand Up @@ -784,7 +784,7 @@ protected function stripTagAttributes($word)
* @param int $startInNew
* @param int $endInNew
*
* @return Match|null
* @return MatchingBlock|null
*/
protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
{
Expand Down Expand Up @@ -837,7 +837,7 @@ protected function findMatch($startInOld, $endInOld, $startInNew, $endInNew)
!$this->isOnlyWhitespace($this->array_slice_cached($this->oldWords, $bestMatchInOld, $bestMatchSize))
)
) {
return new Match($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
return new MatchingBlock($bestMatchInOld, $bestMatchInNew, $bestMatchSize);
}

return null;
Expand Down
31 changes: 0 additions & 31 deletions lib/Caxy/HtmlDiff/Match.php

This file was deleted.

35 changes: 35 additions & 0 deletions lib/Caxy/HtmlDiff/MatchingBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Caxy\HtmlDiff;

/**
* A (string) block of text is the same between the two provided versions.
*/
class MatchingBlock implements \Countable
{
public $startInOld;
public $startInNew;
public $size;

public function __construct(int $startInOld, int $startInNew, int $size)
{
$this->startInOld = $startInOld;
$this->startInNew = $startInNew;
$this->size = $size;
}

public function endInOld() : int
{
return ($this->startInOld + $this->size);
}

public function endInNew() : int
{
return ($this->startInNew + $this->size);
}

public function count() : int
{
return (int)$this->size;
}
}
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset>
<file>./lib</file>
<file>./tests</file>
<rule ref="PSR2" />
</ruleset>
48 changes: 19 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"
bootstrap="./tests/Caxy/Tests/TestInit.php"
>

<groups>
<exclude>
<group>performance</group>
</exclude>
</groups>

<testsuites>
<testsuite name="php-htmldiff Test Suite">
<directory>./tests/Caxy/Tests/HtmlDiff</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>

xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./lib</directory>
</include>
</coverage>
<groups>
<exclude>
<group>performance</group>
</exclude>
</groups>
<testsuites>
<testsuite name="php-htmldiff Test Suite">
<directory>./tests/Caxy/Tests/HtmlDiff</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 4 additions & 2 deletions tests/Caxy/Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Caxy\Tests;

abstract class AbstractTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;

abstract class AbstractTest extends TestCase
{
protected function stripExtraWhitespaceAndNewLines($text)
{
Expand All @@ -14,4 +16,4 @@ protected function stripExtraWhitespaceAndNewLines($text)
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HTMLPurifierConfigTest extends AbstractTest
*/
protected $config;

public function setUp()
public function setUp() : void
{
$config = \HTMLPurifier_Config::createDefault();

Expand Down Expand Up @@ -73,4 +73,4 @@ public function testHtmlDiffConfigStatic()
$diff->setHTMLPurifierConfig($this->config);
$diff->build();
}
}
}

0 comments on commit db8bd20

Please sign in to comment.