PHPackages                             phospr/quantity - 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. phospr/quantity

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

phospr/quantity
===============

PHP value objects for quantities

v1.2.0(10y ago)112.7k2[2 issues](https://github.com/phospr/quantity/issues)MITPHPPHP &gt;=5.3.0

Since May 13Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (18)Used By (0)

Phospr/Quantity
===============

[](#phosprquantity)

[![Build Status](https://camo.githubusercontent.com/06106fe2cff21d3acadcfcf134edce7dc4a38c1d559127b92d402e48505dde6a/68747470733a2f2f7472617669732d63692e6f72672f70686f7370722f7175616e746974792e737667)](https://travis-ci.org/phospr/quantity)[![Coverage Status](https://camo.githubusercontent.com/b7ec75d5017fd6cb117b54979326789c5f83eb44b3c5cde5f357c8ad6c7015ab/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70686f7370722f7175616e746974792f62616467652e737667)](https://coveralls.io/github/phospr/quantity)

A library to represent various quantities as value objects with the ability to convert from one Unit of Measurement to another. Inspired by [mathiasverraes/money](https://github.com/mathiasverraes/money/).

A Quantity is made up of an amount (expressed as a [Fraction](https://github.com/phospr/fraction)) and a Uom (Unit of Measure).

Currently, only Weight is implemented, but other possibilities include Quantity, Volume, Length etc.

```
$weight = new Weight(new Fraction(14), new Uom('OZ'));
```

Usage
-----

[](#usage)

#### Creating Uoms

[](#creating-uoms)

Units of Measure can be created in the following manner. These two examples are equivalent:

```
$pounds = new Uom('LB');
$pounds = Uom::LB();
```

#### Creating Quantities

[](#creating-quantities)

Quantities can be created in any of the following ways. These three examples are equivalent:

```
$weight = new Weight(new Fraction(10), new Uom('LB'));
$weight = new Weight(new Fraction(10), Uom::LB());
$weight = Weight::LB(10);
```

#### Converting Quantities

[](#converting-quantities)

In the following example, we convert 2 lb (pounds) into ounces:

```
echo Weight::LB(2)->to(Uom::OZ()); // 32
```

#### Using Fractions

[](#using-fractions)

The amount part of a Quantity is expressed as a [Fraction](https://github.com/phospr/fraction). This allows us to convert Quantities accurately:

```
echo Weight::OZ(28)->to(Uom::LB()); // 1 3/4 LB
```

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

[](#installation)

```
{
    "require": {
        "phospr/quantity": "dev-master"
    }
}
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 53.7% 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 ~17 days

Recently: every ~7 days

Total

17

Last Release

3796d ago

Major Versions

v0.12.0 → v1.0.02016-01-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f7a54fbc3ac6dfedf6fb7d34386c2d95aa9dae6c1ac706134b849a8ce5355e2?d=identicon)[tomhv](/maintainers/tomhv)

---

Top Contributors

[![tomhv](https://avatars.githubusercontent.com/u/301805?v=4)](https://github.com/tomhv "tomhv (22 commits)")[![imctomhv](https://avatars.githubusercontent.com/u/24391197?v=4)](https://github.com/imctomhv "imctomhv (16 commits)")[![cmtatro](https://avatars.githubusercontent.com/u/438305?v=4)](https://github.com/cmtatro "cmtatro (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phospr-quantity/health.svg)

```
[![Health](https://phpackages.com/badges/phospr-quantity/health.svg)](https://phpackages.com/packages/phospr-quantity)
```

###  Alternatives

[pattern-lab/edition-drupal-standard

Standard Edition of Pattern Lab for Drupal.

12419.1k](/packages/pattern-lab-edition-drupal-standard)[humanmade/hm-redirects

Simple plugin for handling WordPress redirects in a scalable manner.

29245.2k6](/packages/humanmade-hm-redirects)[stuttter/wp-user-groups

Group users together with taxonomies &amp; terms

514.4k](/packages/stuttter-wp-user-groups)

PHPackages © 2026

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