Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: CI

on:
Comment on lines +1 to +3
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
name: PHP ${{ matrix.php-version }} Test
runs-on: ubuntu-22.04
permissions:
Comment thread
Copilot marked this conversation as resolved.
contents: read

strategy:
fail-fast: false
matrix:
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: dom, mbstring
coverage: ${{ matrix.php-version == '8.3' && 'xdebug' || 'none' }}

- name: Validate composer.json
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Run test suite
run: vendor/bin/phpunit ${{ matrix.php-version == '8.3' && '--coverage-clover=coverage.xml' || '' }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: matrix.php-version == '8.3'
with:
files: ./coverage.xml
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

code-quality:
name: Code Quality
runs-on: ubuntu-22.04
permissions:
contents: read
Comment on lines +59 to +62

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: dom, mbstring
tools: cs2pr

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-8.3-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-8.3-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Run PHP_CodeSniffer
shell: bash
run: set -o pipefail && vendor/bin/phpcs --report=checkstyle | cs2pr
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ vendor/
/demo/bower_components
/demo/node_modules
.DS_Store
.idea
.idea
.phpunit.result.cache
coverage.xml
138 changes: 0 additions & 138 deletions .scrutinizer.yml

This file was deleted.

10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
php-htmldiff
============

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/caxy/php-htmldiff/badges/quality-score.png?b=master)][badge_score]
[![Build Status](https://scrutinizer-ci.com/g/caxy/php-htmldiff/badges/build.png?b=master)][badge_status]
[![Code Coverage](https://scrutinizer-ci.com/g/caxy/php-htmldiff/badges/coverage.png?b=master)][badge_coverage]
[![CI](https://github.com/caxy/php-htmldiff/workflows/CI/badge.svg)][badge_ci]
[![Code Coverage](https://codecov.io/gh/caxy/php-htmldiff/branch/master/graph/badge.svg)][badge_coverage]
[![Packagist](https://img.shields.io/packagist/dt/caxy/php-htmldiff.svg)][badge_packagist]
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/caxy/php-htmldiff.svg)][badge_resolve]
[![Percentage of issues still open](http://isitmaintained.com/badge/open/caxy/php-htmldiff.svg)][badge_issues]
Expand Down Expand Up @@ -213,9 +212,8 @@ php-htmldiff is available under [GNU General Public License, version 2][gnu]. Se
* Add documentation on alternative htmldiff engines and perhaps some comparisons


[badge_score]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master
[badge_status]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/build-status/master
[badge_coverage]: https://scrutinizer-ci.com/g/caxy/php-htmldiff/?branch=master
[badge_ci]: https://github.com/caxy/php-htmldiff/actions/workflows/ci.yml
[badge_coverage]: https://codecov.io/gh/caxy/php-htmldiff
[badge_packagist]: https://packagist.org/packages/caxy/php-htmldiff
[badge_resolve]: http://isitmaintained.com/project/caxy/php-htmldiff "Average time to resolve an issue"
[badge_issues]: http://isitmaintained.com/project/caxy/php-htmldiff "Percentage of issues still open"
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"doctrine/cache": "~1.0"
"doctrine/cache": "~1.0",
"squizlabs/php_codesniffer": "^3.7"
},
"suggest": {
"doctrine/cache": "Used for caching the calculated diffs using a Doctrine Cache Provider"
Expand Down
19 changes: 9 additions & 10 deletions lib/Caxy/HtmlDiff/HtmlDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ protected function isClosingIsolatedDiffTag($item, $currentIsolatedDiffTag = nul
protected function performOperation($operation)
{
switch ($operation->action) {
case 'equal' :
case 'equal':
$this->processEqualOperation($operation);
break;
case 'delete' :
case 'delete':
$this->processDeleteOperation($operation, 'diffdel');
break;
case 'insert' :
case 'insert':
$this->processInsertOperation($operation, 'diffins');
break;
case 'replace':
Expand Down Expand Up @@ -334,7 +334,7 @@ protected function diffIsolatedPlaceholder($operation, $pos, $placeholder, $stri
} elseif ($this->isImagePlaceholder($placeholder)) {
return $this->diffElementsByAttribute($oldText, $newText, 'src', 'img');
} elseif ($this->isPicturePlaceholder($placeholder)) {
return $this->diffPicture($oldText, $newText);
return $this->diffPicture($oldText, $newText);
}

return $this->diffElements($oldText, $newText, $stripWrappingTags);
Expand Down Expand Up @@ -401,7 +401,8 @@ protected function diffTables($oldText, $newText)
*
* @return string
*/
protected function diffPicture($oldText, $newText) {
protected function diffPicture($oldText, $newText)
{
if ($oldText !== $newText) {
return sprintf(
'%s%s',
Expand All @@ -410,7 +411,7 @@ protected function diffPicture($oldText, $newText) {
);
}
return $this->diffElements($oldText, $newText);
}
}

protected function diffElementsByAttribute($oldText, $newText, $attribute, $element)
{
Expand Down Expand Up @@ -567,8 +568,7 @@ protected function insertTag($tag, $cssClass, &$words)

$workTag = $this->extractConsecutiveWords($words, 'tag');

if (
isset($workTag[0]) === true &&
if (isset($workTag[0]) === true &&
$this->isOpeningTag($workTag[0]) === true &&
$this->isClosingTag($workTag[0]) === false
) {
Expand Down Expand Up @@ -848,8 +848,7 @@ protected function oldTextIsOnlyWhitespace(int $startingAtWord, int $wordCount)
$this->resetCache = false;
}

if (
$cache !== null &&
if ($cache !== null &&
$lastWordCount === $wordCount &&
$lastStartingWordOffset === $startingAtWord
) { // Hit
Expand Down
3 changes: 1 addition & 2 deletions lib/Caxy/HtmlDiff/ListDiffLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ private function getInnerHtml(DOMNode $node) : string
{
$bufferDom = new DOMDocument('1.0', 'UTF-8');

foreach($node->childNodes as $childNode)
{
foreach ($node->childNodes as $childNode) {
$bufferDom->appendChild($bufferDom->importNode($childNode, true));
}

Expand Down
4 changes: 3 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<ruleset>
<file>./lib</file>
<file>./tests</file>
<rule ref="PSR2" />
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength"/>
</rule>
</ruleset>
2 changes: 0 additions & 2 deletions tests/Caxy/Tests/HtmlDiff/HtmlFileIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected function loadHtmlFile($key)
$filename = $this->files[$key];

if (!isset($this->loadedDiffs[$filename])) {

$html = file_get_contents($filename);

$this->loadedDiffs[$filename] = [
Expand All @@ -71,7 +70,6 @@ protected function loadHtmlFile($key)
$this->parseTagContent('expected', $html),
$this->configXmlToArray($this->parseTagContent('options', $html)),
];

}

return $this->loadedDiffs[$filename];
Expand Down
3 changes: 2 additions & 1 deletion tests/Caxy/Tests/HtmlDiff/Performance/PerformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public function testParagraphPerformance()
$diff = new HtmlDiff(
file_get_contents(self::FIXTURE_PATH . 'paragraphs.html'),
file_get_contents(self::FIXTURE_PATH . 'paragraphs_changed.html'),
'UTF-8', array()
'UTF-8',
array()
);

$output = $diff->build();
Expand Down
Loading