PHPackages                             hyperized/value-objects - 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. hyperized/value-objects

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

hyperized/value-objects
=======================

A basic value objects collection

v2.0.0(2mo ago)68.4k13MITPHPPHP ^8.4CI failing

Since May 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/hyperized/value-objects)[ Packagist](https://packagist.org/packages/hyperized/value-objects)[ RSS](/packages/hyperized-value-objects/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (5)Versions (22)Used By (3)

Value Objects
=============

[](#value-objects)

[![FOSSA Status](https://camo.githubusercontent.com/32efd229fa356a44b2591b140c2c7626f61a0858e30546dab01da912cbe02903/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466879706572697a656425324676616c75652d6f626a656374732e7376673f747970653d736869656c64)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhyperized%2Fvalue-objects?ref=badge_shield)

A typed, immutable value objects collection for PHP 8.4+.

All value objects validate on construction, are immutable (`readonly` classes), and follow the same pattern: extend an abstract, get validation for free.

Install
-------

[](#install)

```
composer require hyperized/value-objects
```

Quick start
-----------

[](#quick-start)

Use the provided concrete classes directly:

```
use Hyperized\ValueObjects\Concretes\Strings\Email;
use Hyperized\ValueObjects\Concretes\Integers\Port;

$email = Email::fromString('user@example.com');
$email->getLocalPart(); // 'user'
$email->getDomain();    // 'example.com'

$port = Port::fromInteger(8080);
$port->getValue(); // 8080
```

Or extend an abstract to create your own domain-specific value object:

```
use Hyperized\ValueObjects\Abstracts\Integers\AbstractPositiveInteger;

readonly class UserId extends AbstractPositiveInteger {}

$id = UserId::fromInteger(42);
$id->getValue(); // 42
```

Available value objects
-----------------------

[](#available-value-objects)

### Integers

[](#integers)

ClassDescription`Integer`Any integer value`PositiveInteger`Must be &gt; 0`NegativeInteger`Must be &lt; 0`NonNegativeInteger`Must be &gt;= 0`RangedInteger`Within a min/max range (defaults to `PHP_INT_MIN`/`PHP_INT_MAX`)`Octal`Valid octal number with decimal conversion`Hexadecimal`Hex string parsing with `asHexString()``Port`Network port (1-65535)### Real numbers

[](#real-numbers)

ClassDescription`RealNumber`Any float value`Percentage`Float between 0-100, with `asFraction()`### Spatial

[](#spatial)

ClassDescription`Coordinate`Latitude (-90/90) and longitude (-180/180) pair`BoundingBox`Southwest/northeast coordinate pair with `contains()``Distance`Non-negative distance with unit conversions (m/km/mi/ft/nm)`Bearing`Compass heading (0-360) with `getCardinal()``Altitude`Height above/below sea level with unit conversions (m/ft)`GeoHash`Base-32 encoded location string with `getPrecision()``Polygon`Ordered list of coordinates (minimum 3 points)`LineString`Ordered list of coordinates (minimum 2 points)### Strings

[](#strings)

ClassDescription`ByteArray`Any string value`EmptyByteArray`Must be empty`NonEmptyByteArray`Must be non-empty`Email`Validated email with `getLocalPart()` / `getDomain()``Url`Validated URL with `getScheme()` / `getHost()` / `getPath()``Uri`URI with scheme requirement, `getQuery()` / `getFragment()``Uuid`RFC 4122 UUID, normalizes to lowercase, `getVersion()``IpAddress`IPv4/IPv6 with `isIPv4()` / `isIPv6()``Hostname`RFC-compliant, max 253 chars, normalized to lowercase`MacAddress`Colon or dash format, normalized to lowercase colon-separated`Json`Validated JSON string with `decode()``Regex`Validated regex pattern with `matches()``SemVer`Semantic version with `getMajor()` / `getMinor()` / `getPatch()``DateString`ISO 8601 / Y-m-d date with `toDateTimeImmutable()`### Lists

[](#lists)

ClassDescription`Inventory`From comma-separated string, with `contains()``ConstrainedList`List with a set of allowed valuesExtending
---------

[](#extending)

Every concrete class extends an abstract that you can extend for your own domain types. Override `validate()` to add custom rules:

```
use Hyperized\ValueObjects\Abstracts\Strings\AbstractEmail;

readonly class CompanyEmail extends AbstractEmail
{
    #[\Override]
    protected static function validate(string $value): void
    {
        parent::validate($value);

        if (!str_ends_with($value, '@company.com')) {
            throw new \InvalidArgumentException('Must be a company email');
        }
    }
}
```

See the [examples/](examples/) directory for more usage patterns.

Quality
-------

[](#quality)

```
composer test        # PHPStan (level 9) + PHPUnit
composer infection   # Mutation testing
```

Licence
-------

[](#licence)

MIT

[![FOSSA Status](https://camo.githubusercontent.com/49f65035b79fa42aa28df4cfdf15cd0f31007aa25b265ff70e8d5a82be797111/68747470733a2f2f6170702e666f7373612e636f6d2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466879706572697a656425324676616c75652d6f626a656374732e7376673f747970653d6c61726765)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhyperized%2Fvalue-objects?ref=badge_large)

Author
------

[](#author)

Gerben Geijteman

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 96.8% 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 ~127 days

Recently: every ~82 days

Total

18

Last Release

82d ago

Major Versions

v0.5.0 → v1.0.02026-04-11

v1.1.0 → v2.0.02026-04-11

PHP version history (6 changes)v0.1PHP &gt;=7.4

v0.1.1PHP ^7.4

v0.1.6PHP ^7.4|^8.0

v0.4.0PHP ^8.3|8.4

v1.0.0PHP ^8.3

v2.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c854d21c83b5addf5f6c607968a353ff859d5bf8302659774d71b017f2f20d6?d=identicon)[hyperized](/maintainers/hyperized)

---

Top Contributors

[![hyperized](https://avatars.githubusercontent.com/u/827954?v=4)](https://github.com/hyperized "hyperized (30 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hyperized-value-objects/health.svg)

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

###  Alternatives

[thomaspark/bootswatch

Themes for Bootstrap

14.8k268.8k14](/packages/thomaspark-bootswatch)

PHPackages © 2026

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