PHPackages                             code-pilots/change-set-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. code-pilots/change-set-collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

code-pilots/change-set-collection
=================================

The utility is designed to detect the state of change set relative to two iterables list

1.1.0(3y ago)12.0kMITPHPPHP &gt;=8.1

Since Nov 18Pushed 3y ago3 watchersCompare

[ Source](https://github.com/code-pilots/change-set-collection)[ Packagist](https://packagist.org/packages/code-pilots/change-set-collection)[ Docs](https://github.com/code-pilots/change-set-collection)[ RSS](/packages/code-pilots-change-set-collection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

ChangeSetCollection Util
========================

[](#changesetcollection-util)

The utility is designed to detect the state of change set relative to two iterables list

Installation
------------

[](#installation)

Install the latest version with

```
$ composer require code-pilots/change-set-collection
```

Basic Usage
-----------

[](#basic-usage)

### Example 1:

[](#example-1)

```
$changeSet = new ChangeSetCollection(
    collection1: [
        new User(id: 1, name: 'User 1'),
        new User(id: 5, name: 'User 5'),
        new User(id: 7, name: 'User 7'),
    ],
    collection2: [
        new User(id: 1, name: 'EditedUser 1'),
        new User(id: 10, name: 'NewUser 10'),
    ],
    getId: fn (User $user) => $user->getId(),
);

echo $line = '--------' . PHP_EOL;
foreach ($changeSet as $change) {
    if ($change->isAdd()) {
        echo '+' . $change->element2->getName() . PHP_EOL;
        echo $line;
    } elseif ($change->isEdit()) {
        echo '-' . $change->element1->getName() . PHP_EOL;
        echo '+' . $change->element2->getName() . PHP_EOL;
        echo $line;
    } elseif ($change->isRemove()) {
        echo '-' . $change->element1->getName() . PHP_EOL;
        echo $line;
    }
}
```

Output:

```
--------
-User 1
+EditedUser 1
--------
+NewUser 10
--------
-User 5
--------
-User 7
--------

```

### Example 2:

[](#example-2)

```
// Create and compare change set
$changeSet = new ChangeSetCollection(
    collection1: [
        new Order(id: Uuid::from('00000000-0000-0000-0000-000000000001'), customer: 'Jon'),
        new Order(id: Uuid::from('00000000-0000-0000-0000-000000000002'), customer: 'Doe'),
    ],
    collection2: [
        ['uuid' => '00000000-0000-0000-0000-000000000001', 'customer' => 'Dan'],
        ['uuid' => null, 'customer' => 'Wendy'],
    ],
    getId: fn (User|array $order) => $order instanceof Order ? $order->getId() : $order['uuid'],
);

// Example helper function
$_separator = '--------' . PHP_EOL;
$_writeOutputBlock = static function(string ...$lines) {
    foreach ($lines as $line) {
        echo $line . PHP_EOL;
    }
    echo $_separator;
}

echo $_separator;
foreach ($changeSet as $change) {
    match ($change->state) {
        ChangeState::add => $_writeOutputBlock(
            '+' . $change->element2['customer'],
        ),
        ChangeState::edit => $_writeOutputBlock(
            '-' . $change->element1->getCustomer(),
            '+' . $change->element2['customer'],
        ),
        ChangeState::remove => $_writeOutputBlock(
            '-' . $change->element1->getCustomer(),
        ),
    }
}

echo PHP_EOL . sprintf(
    '[Added: %d], [Edited: %d], [Removed: %d]',
    $changeSet->countAdded(),
    $changeSet->countEdited(),
    $changeSet->countRemoved(),
);
```

Output:

```
--------
-Jon
+Dan
--------
-Doe
--------
+Wendy
--------

[Added: 1], [Edited: 1], [Removed: 1]

```

For contributors
----------------

[](#for-contributors)

### Run tests

[](#run-tests)

Exec: `./vendor/bin/phpunit`

### Run lint

[](#run-lint)

Exec phpstan: `./vendor/bin/phpstan analyse src tests`Exec psalm: `./vendor/bin/psalm`

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

3

Last Release

1101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/18ad25a37dcf8186c37b847a53a7a20fe7ae33ccd6d809d98650f6523b687731?d=identicon)[Fuck4ik](/maintainers/Fuck4ik)

---

Top Contributors

[![Fuck4ik](https://avatars.githubusercontent.com/u/11775707?v=4)](https://github.com/Fuck4ik "Fuck4ik (2 commits)")

---

Tags

phpcollectionchange-set

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/code-pilots-change-set-collection/health.svg)

```
[![Health](https://phpackages.com/badges/code-pilots-change-set-collection/health.svg)](https://phpackages.com/packages/code-pilots-change-set-collection)
```

###  Alternatives

[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[jshannon63/jsoncollect

Supercharge your JSON using collections

154.9k1](/packages/jshannon63-jsoncollect)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
