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
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ updates:
- package-ecosystem: composer
directory: "/"
target-branch: develop
labels:
- "area: dependencies"
schedule:
interval: weekly
groups:
Expand All @@ -14,6 +16,8 @@ updates:
- package-ecosystem: github-actions
directory: "/"
target-branch: develop
labels:
- "area: dependencies"
schedule:
interval: weekly
groups:
Expand Down
235 changes: 191 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,203 @@
name: Build

on:
'on':
push:
branches:
- develop
- "8.*.x"
- develop
- 8.*.x
pull_request:
branches:
- develop
- "8.*.x"
workflow_dispatch:

- develop
- 8.*.x
workflow_dispatch: null
concurrency:
group: "build-${{ github.workflow }}-${{ github.ref }}"
group: build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
matrix:
runs-on: ubuntu-latest
outputs:
php: ${{ steps.php.outputs.versions }}
lowest: ${{ steps.php.outputs.lowest }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Read supported PHP minors
id: php
shell: bash
run: |
constraint="$(jq -r '.require.php' composer.json)"
if [[ ! "$constraint" =~ ^\>=8\.([0-9]+)\ \<8\.([0-9]+)$ ]] || (( BASH_REMATCH[2] != BASH_REMATCH[1] + 1 )); then
echo "require.php must declare exactly one PHP minor as >=8.N <8.N+1, got: $constraint" >&2
exit 1
fi
version="8.${BASH_REMATCH[1]}"
echo "versions=$(jq -cn --arg php "$version" '[$php]')" >> "$GITHUB_OUTPUT"
echo "lowest=$version" >> "$GITHUB_OUTPUT"
validate:
needs:
- matrix
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.matrix.outputs.lowest }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: highest
- name: Validate
run: composer validate --strict
style:
needs:
- matrix
- validate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.matrix.outputs.lowest }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: highest
- name: Style
run: composer format:check
analyse:
needs:
- matrix
- style
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.matrix.outputs.lowest }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: highest
- name: Analyse
run: composer analyse
tests:
name: Tests - PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependencies }}
needs:
- matrix
- analyse
strategy:
fail-fast: true
matrix:
php: ${{ fromJSON(needs.matrix.outputs.php) }}
dependencies:
- lowest
- highest
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: ${{ matrix.dependencies }}
- name: Run tests
run: composer test
security:
needs:
- matrix
- tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.matrix.outputs.lowest }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: highest
- name: Security audit
run: composer security
archive:
needs:
- matrix
- security
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ needs.matrix.outputs.lowest }}
extensions: fileinfo, pdo_sqlite, sqlite3
coverage: none
tools: composer:v2
- name: Install dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
dependency-versions: highest
- name: Verify Composer archive
shell: bash
run: |
mkdir -p /tmp/pharaonic-ci-archive
composer archive --format=zip --dir=/tmp/pharaonic-ci-archive --file=package
unzip -t /tmp/pharaonic-ci-archive/package.zip
quality:
name: Quality gate
if: ${{ always() }}
needs:
- matrix
- validate
- style
- analyse
- tests
- security
- archive
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

# Every branch declares exactly one PHP minor (">=8.N <8.N+1"), so the
# version comes from composer.json. This works on develop and feature
# branches as well as on the 8.N.x lines.
- name: Detect target PHP version
id: php
shell: bash
run: |
constraint="$(jq -r '.require.php' composer.json)"

if [[ ! "$constraint" =~ ^\>=(8\.[0-9]+) ]]; then
echo "Cannot read the target PHP minor from require.php: $constraint" >&2
exit 1
fi

echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ steps.php.outputs.version }}"
coverage: none
tools: composer:v2

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

- name: Check
run: composer check
steps:
- name: Require every stage to succeed
env:
NEEDS_JSON: ${{ toJSON(needs) }}
run: |
python3 - <<'PY_CHECK'
import json, os, sys
results = json.loads(os.environ['NEEDS_JSON'])
failed = {name: job['result'] for name, job in results.items() if job['result'] != 'success'}
if failed:
print('Required stages did not succeed:', failed)
sys.exit(1)
print('Every required stage succeeded.')
PY_CHECK
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
# Creates and updates the labels in .github/labels.yml. Labels that are
# not listed are left alone.
- name: Sync labels
uses: crazy-max/ghaction-github-labeler@v6
uses: crazy-max/ghaction-github-labeler@548a7c3603594ec17c819e1239f281a3b801ab4d # v6.0.0
with:
yaml-file: .github/labels.yml
skip-delete: true
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project are documented here.

## 8.0.1 - Unreleased

### Fixed

- Hunk grouping is written so PHPStan 2.3.7 analyses it without errors; hunks are unchanged.

### Changed

- Internal classes moved out of `Support\` into `Engine\` and `Paths\`, and the unused `Support\Missing` was removed. All of them are `@internal`, so the public API is unchanged.
- The build runs staged checks (validate, style, analysis, tests on lowest and highest dependencies on Ubuntu and Windows, security, archive) behind one Quality gate, and requires PHPUnit 9.6.33 or later for development.

## 8.0.0 - 2026-10-16

### Added
Expand Down
2 changes: 2 additions & 0 deletions MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ One branch per PHP minor, each requiring exactly that minor (`"php": ">=8.0 <8.1
- Options are immutable. Redaction happens before a value is stored in a result, including inside aggregate and subtree values.
- Text diffs keep the low-level `added`/`removed`/`unchanged` lines; modified-line pairing is a layer on top. Unified output must apply with `git apply` and `patch`.
- Every exception implements `Exceptions\DiffException`. Everything marked `@internal` may change in any release.
- The public classes stay directly under `Pharaonic\Diff` and the catch-all `DiffException` interface stays in `Exceptions\`. Both are deliberate: they are published on every line, and moving them to `ValueObjects\` or `Contracts\` would only add aliases.
- Internal code lives with its responsibility: `Engine\` (structured and text diffing and their value handling), `Paths\` (dot notation and path patterns), `Text\`, `Algorithm\` and `Renderer\`.

## Package-specific constraints

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<p align="center">
<a href="https://php.net" target="_blank"><img src="https://img.shields.io/static/v1?label=PHP&message=8.0&color=blue&style=flat-square" alt="PHP Version : 8.0"></a>
<img src="https://img.shields.io/static/v1?label=License&message=MIT&color=brightgreen&style=flat-square" alt="License">
<img src="https://github.com/Pharaonic/php-diff/actions/workflows/build.yml/badge.svg" alt="Tests">
<img src="https://github.com/Pharaonic/php-diff/actions/workflows/build.yml/badge.svg?branch=8.0.x" alt="Build">
<br>
<a href="https://packagist.org/packages/pharaonic/php-diff" target="_blank"><img src="https://img.shields.io/static/v1?label=Packagist&message=pharaonic/php-diff&color=blue&logo=packagist&logoColor=white" alt="Source"></a>
<a href="https://packagist.org/packages/pharaonic/php-diff" target="_blank"><img src="https://poser.pugx.org/pharaonic/php-diff/v" alt="Packagist Version"></a>
<a href="https://packagist.org/packages/pharaonic/php-diff" target="_blank"><img src="https://poser.pugx.org/pharaonic/php-diff/downloads" alt="Packagist Downloads"></a>
</p>

<h3 align="center">Know exactly what changed in PHP data and text.</h3>
<h5 align="center">Added, removed, modified and moved values at their exact paths, records matched by ID, redacted secrets, and GitHub-style line diffs.</h5>
<br>

## Installation
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"description": "Semantic structured diffs and GitHub-style text diffs for PHP: added, removed, modified and moved values with paths, identity-aware lists, redaction, hunks, unified patches and HTML.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Moamen Eltouny (Raggi)",
"email": "raggigroup@gmail.com"
}
],
"keywords": [
"php",
"diff",
Expand All @@ -15,12 +21,6 @@
"change detection",
"pharaonic"
],
"authors": [
{
"name": "Moamen Eltouny (Raggi)",
"email": "raggigroup@gmail.com"
}
],
"homepage": "https://github.com/Pharaonic/php-diff",
"support": {
"docs": "https://pharaonic.dev/packages/php/diff",
Expand All @@ -34,7 +34,8 @@
"require-dev": {
"laravel/pint": "^1.5",
"pestphp/pest": "^1.23",
"phpstan/phpstan": "^2.1"
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^9.6.33"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 23 additions & 0 deletions docs/sections/17-upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Upgrade Guide

Diff has one release line per PHP version, and every line has the same classes, methods and output. This page covers the `8.0.x` line, for PHP 8.0.

### Patch Releases

Patch releases such as `8.0.0` to `8.0.1` never break your code. Update with:

```bash no-line-numbers
composer update pharaonic/php-diff
```

Output changes only to fix a bug, and every such change is listed in the changelog. Classes marked `@internal` (the engines, renderers and text helpers) are not part of the public API and may move or change in any release; don't use them directly.

### Moving To Another PHP Version

No code changes are needed. Composer picks the line that matches your PHP version, so after upgrading PHP run `composer update pharaonic/php-diff`.

The constraint that `composer require` writes (for example `^8.0`) already allows the newer lines. If you pinned a line with a tilde constraint such as `~8.0.0`, widen it first, or Composer stays on `8.0.x` and cannot install on the new PHP version.

### Changelog

Every release is listed in the [changelog](https://github.com/Pharaonic/php-diff/blob/8.0.x/CHANGELOG.md) and on the [GitHub releases](https://github.com/Pharaonic/php-diff/releases) page.
2 changes: 2 additions & 0 deletions docs/sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
- [Troubleshooting](#troubleshooting)
- Community
- [Contributors](#contributors)
- Upgrades
- [Upgrade Guide](#upgrade-guide)
7 changes: 2 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
<testsuite name="Package">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Loading