PHPackages                             kamilwylegala/immutable-setter - 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. kamilwylegala/immutable-setter

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

kamilwylegala/immutable-setter
==============================

Utility class for PHP that helps making your classes immutable.

0.1.1(7y ago)01.0k↓100%MITPHPPHP &gt;=5.4.0

Since Jul 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kamilwylegala/immutable-setter)[ Packagist](https://packagist.org/packages/kamilwylegala/immutable-setter)[ RSS](/packages/kamilwylegala-immutable-setter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Immutable Setter
================

[](#immutable-setter)

Tiny utillity class that helps you making your classes immutable by adding *wither* methods.

*Inspired by Lombok's @Wither annotation.*

It lets you easily add `witherX` methods to clone object with modified one property.

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

[](#installation)

Use composer to get library from packagist:

```
$ php composer.phar require kamilwylegala/immutable-setter

```

Usage
-----

[](#usage)

1. Add `wither` field to your class.
2. Assign `new Wither($this, ["arg1", "arg2"])` to this field and provide constructor schema with proper order of arguments. You can also skip second argument and let `Wither` resolve constructor arguments automatically.
3. Add public `withArg1` method to your class and put:

```
return $this->wither->getInstance("arg1", $newArg1)

```

4. Running `$valueObject->withArg1($newArg1)` will create copy of your object with changed `$arg1` field.

### Example

[](#example)

```
use KamilWylegala\ImmutableSetter\Wither;

class Person
{

    private $name;
    private $age;

    private $wither;

    public function __construct($name, $age)
    {
        $this->name = $name;
        $this->age = $age;

        $this->wither = new Wither($this, ["name", "age"]); //Second param is optional.
    }

    public function withName($newName)
    {
        return $this->wither->getInstance("name", $newName);
    }

}
```

Tests
-----

[](#tests)

Install dev dependencies and run in root:

```
$ vendor/bin/phpunit

```

Licence
-------

[](#licence)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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 ~331 days

Total

2

Last Release

2905d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/12d5f8418007e5407d014b1796a756412cc8d83f56ae95ecabe426ce4f2c089e?d=identicon)[kamilwylegala](/maintainers/kamilwylegala)

---

Top Contributors

[![kamilwylegala](https://avatars.githubusercontent.com/u/10462494?v=4)](https://github.com/kamilwylegala "kamilwylegala (11 commits)")

---

Tags

setterimmutablewither

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kamilwylegala-immutable-setter/health.svg)

```
[![Health](https://phpackages.com/badges/kamilwylegala-immutable-setter/health.svg)](https://phpackages.com/packages/kamilwylegala-immutable-setter)
```

###  Alternatives

[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[innmind/immutable

Immutable PHP primitive wrappers

75218.0k74](/packages/innmind-immutable)[rtlopez/decimal

An object oriented immutable arbitrary-precision arithmetic library for PHP

27262.8k2](/packages/rtlopez-decimal)[aeon-php/calendar-holidays

Holidays calendar abstraction layer for Aeon Time management framework

14212.4k3](/packages/aeon-php-calendar-holidays)[aeon-php/business-hours

Abstraction allowing to define and check against business hours

10135.8k](/packages/aeon-php-business-hours)

PHPackages © 2026

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