PHPackages                             cloudcreativity/utils-value - 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. cloudcreativity/utils-value

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

cloudcreativity/utils-value
===========================

Library to handle standard scalar values in PHP.

v3.0.0(8mo ago)010.5k↓14%Apache-2.0PHPPHP ^8.2CI passing

Since May 14Pushed 8mo ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (11)Used By (0)

cloudcreativity/utils-value
===========================

[](#cloudcreativityutils-value)

A small library to handle scalar values that have meaning.

Values
------

[](#values)

It is common to handle scalar values that have particular meaning to your application. For instance, if objects in your applications expect a string that can only be one of several different string values - e.g. `lead`, `follow` for describing dance roles - then any object that expects those values would always have to check that the string received matches those two options. For example:

```
public function setRole($value) {
  if (!in_array($value, ['lead', 'follow'])) {
    throw new \InvalidArgumentException('Expecting a valid dance role.');
  }

  // ...
}
```

This becomes highly repetitive - plus if you wanted to add `either` as a valid value, you'd need to update it in every `in_array()` call across the application.

This is where we'd use the `CloudCreativity\Utils\Value\AbstractValue`class from this package. For example:

```
use CloudCreativity\Utils\Value\AbstractValue;

class DanceRole extends AbstractValue
{

  protected function accept($value): bool
  {
    return in_array($value, ['lead', 'follow'], true);
  }
}
```

The original setter shown above would then become:

```
public function setRole(DanceRole $role)
{
  // no need to check it as we know it is valid.
}
```

Helper Methods
--------------

[](#helper-methods)

Quite often we find it is useful for the value object to have helper methods. By implementing these on the value object, they become available to any part of your application that receives an instance of the value.

For instance, or `DanceRole` object could look like this:

```
class DanceRole extends AbstractValue
{

  public function isLead(): bool
  {
    return $this->is('lead');
  }

  public function isFollow(): bool
  {
    return $this->is('follow');
  }

  // ...
}
```

Trait
-----

[](#trait)

If you do not want to extend the abstract class, the majority of methods are available via the `ValueTrait`.

Interface
---------

[](#interface)

This package defines an interface, `ValueInterface`, to ensure consistency across value objects:

- `__toString()` : so that a scalar value can always be written to a string.
- `toString()` : so that a scalar value can fluently be cast to a string.
- `jsonSerialize()` : so that a scalar value can always be cast properly when being JSON encoded.
- `get()` : gets the underlying scalar value, e.g. would return a string if the value object holds a string.
- `is(...$values)` : compares provided values to the underlying scalar value, returning `true` if the value matches any of them.

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance61

Regular maintenance activity

Popularity24

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~735 days

Total

9

Last Release

248d ago

Major Versions

v0.2.0 → v1.0.02017-01-30

v1.2.0 → v2.0.02018-06-11

v2.2.0 → v3.0.02025-09-12

PHP version history (6 changes)v0.1.0PHP &gt;=5.5.0

v1.0.0PHP &gt;=5.6.0

v1.1.0PHP ^5.6|^7.0

v2.0.0PHP ^7.1.3

v2.1.0PHP ^7.1.3|^8.0

v3.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca1ed60931eb66b875b4bad2b1a8a5093c14d5225cf72c3d6c3fd403982ec7cf?d=identicon)[lindyhopchris](/maintainers/lindyhopchris)

---

Top Contributors

[![lindyhopchris](https://avatars.githubusercontent.com/u/4464333?v=4)](https://github.com/lindyhopchris "lindyhopchris (68 commits)")

---

Tags

phpvalue-objectvaluescalar

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cloudcreativity-utils-value/health.svg)

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

###  Alternatives

[brysem/phpenums

Enums made simple in PHP.

10171.5k](/packages/brysem-phpenums)[jaybizzle/hasmeta

Access model meta data as if it was a property on your model

291.9k](/packages/jaybizzle-hasmeta)[space48/auto-value

Generated immutable value classes for PHP7.1+

291.6k](/packages/space48-auto-value)

PHPackages © 2026

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