PHPackages                             githubjeka/value-object - 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. githubjeka/value-object

ActiveLibrary

githubjeka/value-object
=======================

Help to create immutable Value Objects

v1.0.0(10y ago)229MITPHPPHP &gt;=5.4.0

Since Jan 25Pushed 10y ago1 watchersCompare

[ Source](https://github.com/githubjeka/value-object)[ Packagist](https://packagist.org/packages/githubjeka/value-object)[ Docs](https://github.com/githubjeka/value-object)[ RSS](/packages/githubjeka-value-object/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Trait Value Object
==================

[](#trait-value-object)

Help to create immutable Value Objects

[![Build Status](https://camo.githubusercontent.com/66e0f824499187bd802ad940e17b3c9420a53132cb0fee0959581dc9c6792504/68747470733a2f2f7472617669732d63692e6f72672f6769746875626a656b612f76616c75652d6f626a6563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/githubjeka/value-object)

Default API
-----------

[](#default-api)

Two methods [`compareTo`](https://github.com/githubjeka/value-object/blob/master/src/ImmutableValueObject.php#L64-L86)and [`changeTo`](https://github.com/githubjeka/value-object/blob/master/src/ImmutableValueObject.php#L64-L86):

```
// Value Object is a Metre(['1', 'centimeter'])
$metre = new Metre(['1', 'cm']);
$metre->compareTo([2,'cm']); // returns -1
$metre->compareTo([.1,'m']); // returns 0
$metre->compareTo([1,'mm']); // returns 1
$metre->changeTo([1,'m']) //returns new  Metre(['1', 'm']), $metre is  Metre(['1', 'centimeter'])

//user API via changeTo
$metre->toMillimeter(); // new Metre(['10', 'mm']), $metre is  Metre(['1', 'centimeter'])
$metre->toMillimeter()->add([1,'mm'])->getAmount();  //returns 11

// rewrite __toString()
echo $metre // returns '1'
```

### a little more

[](#a-little-more)

```
final class Money
{
    use ImmutableValueObject;

    private $amount;
    private $currency;

    protected function compare($valueObject)
    {
        return bccomp($this->toUsd()->amount, $valueObject->toUsd()->amount);
    }

    protected function setAttributes($value)
    {
        // ... validate value

        $this->currency = $value[1];
        $this->amount = $value[0];
    }

    private function getCurrencies()
    {
        return [
            'usd' => 1,
            'rub' => 60,
            //...
        ];
    }

    public function toUsd()
    {
        if ($this->currency === 'usd') {
            return $this->changeTo([$this->amount, 'usd']);
        }
        $k = $this->getCurrencies()[$this->currency];
        return $this->changeTo([$this->amount * $k, 'usd']);
    }

    public function toRub()
    {
        $amount = $this->toUsd()->amount;
        $k = $this->getCurrencies()['rub'];
        return $this->changeTo([$amount / $k, 'rub']);
    }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3756d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ddab25b4518a59d7c831acc7abc94c849f900b64fa35a8e1018babdda715b16?d=identicon)[githubjeka](/maintainers/githubjeka)

---

Top Contributors

[![githubjeka](https://avatars.githubusercontent.com/u/874234?v=4)](https://github.com/githubjeka "githubjeka (7 commits)")

---

Tags

value objectsimmutable

### Embed Badge

![Health badge](/badges/githubjeka-value-object/health.svg)

```
[![Health](https://phpackages.com/badges/githubjeka-value-object/health.svg)](https://phpackages.com/packages/githubjeka-value-object)
```

###  Alternatives

[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[darsyn/ip

An immutable IP Address value object that provides several different notations, including helper functions.

2572.0M20](/packages/darsyn-ip)[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.0k73](/packages/innmind-immutable)[smartemailing/types

Lightweight collection of handy PHP value objects

9368.7k1](/packages/smartemailing-types)[vasek-purchart/doctrine-date-time-immutable-types

Doctrine DateTimeImmutable types

42228.3k](/packages/vasek-purchart-doctrine-date-time-immutable-types)

PHPackages © 2026

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