PHPackages                             ayeo/price - 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. ayeo/price

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

ayeo/price
==========

Simple price model

2.0.6(3y ago)024.1k↑350%1MITPHPPHP &gt;=7.4CI failing

Since Oct 16Pushed 3y ago7 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (23)Used By (0)

[![Build Status](https://github.com/ayeo/price/workflows/tests/badge.svg)](https://github.com/ayeo/price/workflows/tests/badge.svg)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Packagist Version](https://camo.githubusercontent.com/bdb18bff9abdd9c8b75cfcd555c1286e88bfdd0b971030d6e91436d7fadb7d18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6179656f2f70726963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ayeo/price)[![Coverage](https://camo.githubusercontent.com/dc8ad890508dbf31986fb83ff8d634e3367adf57ea904e898e07825ab7baf117/68747470733a2f2f636f6465636f762e696f2f67682f6179656f2f70726963652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/ayeo/price)

Price
=====

[](#price)

Simple DDD price model. The goal is to make model usage as easy as possible. Creating object is easy and dont require any additional objects. Object acts as Value Object - is immutable and self-validating. It is designed to be side effect free.

API
===

[](#api)

Building
--------

[](#building)

```
$price = new Price(float $nett, float $gross, "GBP")
$price = Price::buildByNett(float $nett, integer $tax, "USD") - returns Price
$price = Price::buildByGross(float $gross, integer $tax, "EUR") - returns Price
```

Tax
---

[](#tax)

Tax aspects may be a bit confusing at first glance. You may need to build price providing tax rate:

```
$price = Price::buildByNett(100.00, 8, "USD"):
```

In this case tax rate is known and it is equal to 8%. When you adding or subtracting prices with same tax rate the result price will come up with same rate. But if you operate with different rates result price has unknown tax rate.

```
$A = Price::buildByNett(100.00, 8, "USD"):
$B = Price::buildByNett(10.00, 11, "USD"):
$C = $A->add($B);
$C->hasTaxRate(); //returns false
```

You can still get tax percentage value (but it is not the rate!) using:

```
$C->getTax()->getValue();
```

Operations
----------

[](#operations)

```
$priceA->add(Price $priceB) - returns Price
$priceA->subtract(Price $priceB) - returns Price
$priceA->multiply(integer $times) - returns Price

$priceA->addGross(float $value) - returns Price
$priceA->subtractGross(float $value) - returns Price
```

Immutable
=========

[](#immutable)

Operations creates new instances

```
$A = new Price(100.00, 120.00, 'USD');
$B = new Price(10.00, 12.00, 'USD');

$sum = $A->add($B);
$sum->getGross(); //returns 132.00
$A->getGross(); //returns 120.00
$B->getGross(); //returns 12.00
```

Comparing
---------

[](#comparing)

```
$priceA->isEqual(Price $priceB) - returns bool
$priceA->isLower(Price $priceB) - returns bool
$priceA->isGreater(Price $priceB) - returns bool
```

Constraints
===========

[](#constraints)

- Nett and gross must be positive
- Gross must not be lower than nett
- Tax must be integer
- Currency symbol is optional but if appears must follow iso 4217 (3 uppercase chars)

Todo
====

[](#todo)

There exists currencies with different precision than 2. The map must be developed. [https://en.wikipedia.org/wiki/ISO\_4217#Active\_codes](https://en.wikipedia.org/wiki/ISO_4217#Active_codes)

Contributing
============

[](#contributing)

Feel free to PR, tests must pass.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor3

3 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 ~132 days

Recently: every ~234 days

Total

21

Last Release

1210d ago

Major Versions

1.0.16 → 2.0.32020-09-07

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

2.0.3PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![ayeo](https://avatars.githubusercontent.com/u/60191?v=4)](https://github.com/ayeo "ayeo (6 commits)")[![pbabilas](https://avatars.githubusercontent.com/u/901050?v=4)](https://github.com/pbabilas "pbabilas (4 commits)")[![veylib](https://avatars.githubusercontent.com/u/22482223?v=4)](https://github.com/veylib "veylib (3 commits)")[![maureis](https://avatars.githubusercontent.com/u/6088053?v=4)](https://github.com/maureis "maureis (2 commits)")[![lkowol](https://avatars.githubusercontent.com/u/21098815?v=4)](https://github.com/lkowol "lkowol (2 commits)")[![lukaskolista](https://avatars.githubusercontent.com/u/15650502?v=4)](https://github.com/lukaskolista "lukaskolista (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![Temhun](https://avatars.githubusercontent.com/u/24705130?v=4)](https://github.com/Temhun "Temhun (1 commits)")[![BubakPL](https://avatars.githubusercontent.com/u/12608263?v=4)](https://github.com/BubakPL "BubakPL (1 commits)")

---

Tags

modelprice

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ayeo-price/health.svg)

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

###  Alternatives

[scrumble-nl/laravel-model-ts-type

This package makes it possible to generate TypeScript types based on your models

6984.5k](/packages/scrumble-nl-laravel-model-ts-type)[gbrock/laravel-table

Table functionality for Laravel models

7644.3k](/packages/gbrock-laravel-table)[michalsn/codeigniter4-uuid

UUID and ULID package for CodeIgniter 4 with support for Model.

4728.7k4](/packages/michalsn-codeigniter4-uuid)[brysem/phpenums

Enums made simple in PHP.

10171.5k](/packages/brysem-phpenums)[mpociot/reanimate

Undo Laravel soft deletes

1221.2k](/packages/mpociot-reanimate)[adamhopkinson/laravel-model-hash

A trait which automatically generates a unique hash per model instance

2318.7k](/packages/adamhopkinson-laravel-model-hash)

PHPackages © 2026

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