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

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

lokeland/shipping-value-objects
===============================

Collection of value objects regularly used when working with products and shipping.

0.1.1(3y ago)121[2 PRs](https://github.com/lokeland/shipping-value-objects/pulls)MITPHPPHP ^8.1

Since Jan 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/lokeland/shipping-value-objects)[ Packagist](https://packagist.org/packages/lokeland/shipping-value-objects)[ Docs](https://github.com/lokeland/shipping-value-objects)[ GitHub Sponsors](https://github.com/lokeland)[ RSS](/packages/lokeland-shipping-value-objects/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

Value objects for working with shipping attributes
==================================================

[](#value-objects-for-working-with-shipping-attributes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e465e94aa559c29f42cc5b9292b7b24abe334e3c0629385a9ef4a8acc14e2d31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6b656c616e642f7368697070696e672d76616c75652d6f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lokeland/shipping-value-objects)[![Tests](https://camo.githubusercontent.com/853b787b068efa37b2bc36ecbef119ab02c86cea0fc1236f901014d4a5439d0f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6f6b656c616e642f7368697070696e672d76616c75652d6f626a656374732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/lokeland/shipping-value-objects/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/77c17141f8cd78aa0b528d785ece8f8327ab3d6248faacfacf86ebdb9c562d4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6b656c616e642f7368697070696e672d76616c75652d6f626a656374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lokeland/shipping-value-objects)

This library contains a set of value objects regularly used when working with products and shipping. In addition to that it also comes with a couple of custom collections extended from `Illuminate\Collections` (from Laravel).

Things to note:

- All operations on value objects are immutable.
- Only the most relevant (metric) units is added, but you're welcome to submit a pull request.

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

[](#installation)

You can install the package via composer:

```
composer require lokeland/shipping-value-objects
```

Usage
-----

[](#usage)

### Value objects

[](#value-objects)

#### Weight

[](#weight)

```
use Lokeland\SVO\Weight;

$weight = Weight::fromGrams(100);
$weight = Weight::fromKilos(100);
$weight = Weight::ofZero();

$weight->toGrams();
$weight->toKilos();

$weight->add(Weight::fromGrams(50));
$weight->subtract(Weight::fromGrams(50));
$weight->multiply(2);

$weight->isZero();
$weight->equal(Weight::fromGrams(50));
$weight->equalOrGreaterThan(Weight::fromGrams(50));
$weight->equalOrLessThan(Weight::fromGrams(50));
$weight->greaterThan(Weight::fromGrams(50));
$weight->lessThan(Weight::fromGrams(50));
$weight->isBetween(
    Weight::fromGrams(10),
    Weight::fromGrams(70)
);
```

> **Note**Values are stored as grams internally

#### Measurement

[](#measurement)

```
use Lokeland\SVO\Measurement;

$measurement = Measurement::fromMillimeters(100);
$measurement = Measurement::fromCentimeters(100);
$measurement = Measurement::fromDecimeter(100);
$measurement = Measurement::fromMeters(100);

$measurement->toMillimeters();
$measurement->toCentimeters();
$measurement->toDecimeter();
$measurement->toMeters();

$measurement->isZero();
$measurement->add(Measurement::fromCentimeters(50));
$measurement->subtract(Measurement::fromCentimeters(50));
$measurement->equal(Measurement::fromCentimeters(50));
$measurement->equalOrGreaterThan(Measurement::fromCentimeters(50));
$measurement->equalOrLessThan(Measurement::fromCentimeters(50));
$measurement->greaterThan(Measurement::fromCentimeters(50));
$measurement->lessThan(Measurement::fromCentimeters(50));
$measurement->multiply(2);
$measurement->isBetween(
    Measurement::fromCentimeters(10),
    Measurement::fromCentimeters(70)
);
```

> **Note**Values are stored as millimeters internally

#### Dimensions

[](#dimensions)

```
use Lokeland\SVO\Dimensions;
use Lokeland\SVO\Measurement;

$dimensions = Dimensions::make(
    height: Measurement::fromMillimeters(100),
    width: Measurement::fromMillimeters(100),
    length: Measurement::fromMillimeters(100),
);
$dimensions = Dimensions::ofZero();

$dimensions->height;
$dimensions->width;
$dimensions->length;

$dimensions->isZero();

$dimensions->longest();
$dimensions->shortest();

$dimensions->toVolume();
$dimensions->toArray();
```

#### Shipping attributes

[](#shipping-attributes)

```
use Lokeland\SVO\ShippingAttributes;
use Lokeland\SVO\Weight;
use Lokeland\SVO\Dimensions;
use Lokeland\SVO\Measurement;

$shippingAttributes = ShippingAttributes::make(
    weight: Weight::fromKilos(),
    dimensions: Dimensions::make(
        height: Measurement::fromMillimeters(100),
        width: Measurement::fromMillimeters(100),
        length: Measurement::fromMillimeters(100),
    )
);

$shippingAttributes->weight;
$shippingAttributes->dimensions;

$shippingAttributes->toArray();
```

#### Volume

[](#volume)

```
use Lokeland\SVO\Volume;

$volume = Volume::fromCubicMillimeters(10);
$volume = Volume::fromCubicCentimeters(10);
$volume = Volume::fromCubicDecimeters(10);
$volume = Volume::fromCubicMeters(10);

$volume->toCubicMillimeters();
$volume->toCubicCentimeters();
$volume->toCubicDecimeter();
$volume->toCubicMeters();

$volume->isZero();
$volume->add(Volume::fromCubicCentimeters(50));
$volume->subtract(Volume::fromCubicCentimeters(50));
$volume->equal(Volume::fromCubicCentimeters(50));
$volume->equalOrGreaterThan(Volume::fromCubicCentimeters(50));
$volume->equalOrLessThan(Volume::fromCubicCentimeters(50));
$volume->greaterThan(Volume::fromCubicCentimeters(50));
$volume->lessThan(Volume::fromCubicDecimeters(50));
$volume->multiply(2);
$volume->isBetween(
    Volume::fromCubicCentimeters(10),
    Volume::fromCubicCentimeters(70)
);
```

> **Note**Values are stored as cubic millimeters internally

### Collections

[](#collections)

#### Measurement collection

[](#measurement-collection)

```
use Lokeland\SVO\Measurement;
use Lokeland\SVO\MeasurementCollection;

$collection = MeasurementCollection::make([
    Measurement::fromDecimeter(10),
    Measurement::fromDecimeter(20),
    Measurement::fromDecimeter(30),
]);

$collection->findLongest();
$collection->findShortest();
$collection->orderByLongToShort();
$collection->orderByShortToLong();
$collection->sumMeasurements();
```

#### Weight collection

[](#weight-collection)

```
use Lokeland\SVO\Weight;
use Lokeland\SVO\WeightCollection;

$collection = WeightCollection::make([
    Weight::fromKilos(1),
    Weight::fromKilos(2),
    Weight::fromKilos(3),
]);

$collection->findHeaviest();
$collection->findLightest();
$collection->orderByHeavyToLight();
$collection->orderByLightToHeavy();
$collection->sumWeight();
```

### Min and max

[](#min-and-max)

When adding or subtracting a value, you can provide min/max as the second arguments, like this:

```
use Lokeland\SVO\Measurement;

$measurement = Measurement::fromMeters(1);
$measurement->add(
    measurement: Measurement::fromMeters(5),
    max: Measurement::fromMeters(2),
);
$measurement->toMeters(); // 2

$measurement = Measurement::fromMeters(5);
$measurement->subtract(
    measurement: Measurement::fromMeters(4),
    min: Measurement::fromMeters(3)
);
$measurement->toMeters(); // 3
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jarand](https://github.com/lokeland)
- [All Contributors](../../contributors)

Made using [package skeleton from Spatie](https://github.com/spatie/package-skeleton-php).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

2

Last Release

1181d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3435778d45c944584403af1dd46d18cbd31bfed0bf6f29241c0385d737011e95?d=identicon)[lokeland](/maintainers/lokeland)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")[![lokeland](https://avatars.githubusercontent.com/u/6294253?v=4)](https://github.com/lokeland "lokeland (6 commits)")

---

Tags

weightshippingdimensionsvalueobjectslokeland

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[cartalyst/converter

A framework agnostic measurement conversion and formatting package featuring multiple types of measurements and currency conversion.

88434.4k7](/packages/cartalyst-converter)[dsposito/argo

A shipping utility.

23177.0k](/packages/dsposito-argo)[tilleuls/sylius-click-n-collect-plugin

Click and Collect plugin for Sylius, to sell and deliver securely during the COVID-19 pandemic.

7814.2k](/packages/tilleuls-sylius-click-n-collect-plugin)

PHPackages © 2026

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