PHPackages                             gosuperscript/schema-money - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. gosuperscript/schema-money

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

gosuperscript/schema-money
==========================

Monetary extension for Axiom - provides schema types, parsers, and operators for monetary values with strong type safety and currency validation

v0.3.0(2mo ago)01.6k[1 PRs](https://github.com/gosuperscript/axiom-money/pulls)MITPHPPHP ^8.4CI passing

Since Jun 18Pushed 2mo agoCompare

[ Source](https://github.com/gosuperscript/axiom-money)[ Packagist](https://packagist.org/packages/gosuperscript/schema-money)[ Docs](https://github.com/gosuperscript/axiom-money)[ RSS](/packages/gosuperscript-schema-money/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (9)Versions (11)Used By (0)

Axiom Money
===========

[](#axiom-money)

[![Tests](https://github.com/gosuperscript/axiom-money/workflows/Tests/badge.svg)](https://github.com/gosuperscript/axiom-money/actions)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

A monetary extension for [Axiom](https://github.com/gosuperscript/axiom), providing schema types, parsers, and operators for monetary values with strong type safety and currency validation.

**Note:** This library extends [Axiom](https://github.com/gosuperscript/axiom) (built on [gosuperscript/schema](https://github.com/gosuperscript/schema)) with monetary value support.

Features
--------

[](#features)

- **Schema Types**: Type-safe monetary value handling with currency validation
- **Money Parser**: Parse monetary values from various string formats (e.g., "EUR 100", "£50.25")
- **Operator Overloading**: Mathematical operations on Money objects (addition, subtraction, multiplication, division, comparisons)
- **Multiple Type Variants**:
    - `MonetaryType`: Standard monetary type with currency validation
    - `MinorMonetaryType`: Money from minor units (cents, pence, etc.)
    - `DynamicMonetaryType`: Flexible parsing that auto-detects currency
    - `MonetaryIntervalType`: Intervals of monetary values
- **Monetary Intervals**: Support for ranges of monetary values

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- ext-intl extension

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

[](#installation)

Install via Composer:

```
composer require gosuperscript/axiom-money
```

Usage
-----

[](#usage)

### Basic Money Types

[](#basic-money-types)

```
use Brick\Money\Currency;
use Brick\Money\Money;
use Superscript\Axiom\Money\Types\MonetaryType;

// Create a monetary type for EUR
$eurType = new MonetaryType(Currency::of('EUR'));

// Coerce values to Money objects
$money = $eurType->coerce('100.50')->unwrap()->unwrap();
// Result: Money object with EUR 100.50

// Assert existing Money objects
$result = $eurType->assert(Money::of(50, 'EUR'));
// Result: Ok(Some(Money))

// Format money for display
$formatted = $eurType->format(Money::of(100.50, 'EUR'));
// Result: "€100.50"
```

### Money Parser

[](#money-parser)

Parse money from various string formats:

```
use Superscript\Axiom\Money\MoneyParser;
use Brick\Money\Money;

// Parse from "CURRENCY AMOUNT" format
$result = MoneyParser::parse('EUR 100');
$money = $result->unwrap(); // Money object: EUR 100

// Parse from currency symbol format
$result = MoneyParser::parse('£50.25');
$money = $result->unwrap(); // Money object: GBP 50.25

// Parse from "CURRENCY AMOUNT" format
$result = MoneyParser::parse('USD 1000.50');
$money = $result->unwrap(); // Money object: USD 1000.50

// Already a Money object? Just returns it
$existing = Money::of(100, 'EUR');
$result = MoneyParser::parse($existing);
$money = $result->unwrap(); // Same Money object
```

### Minor Units

[](#minor-units)

Work with minor currency units (cents, pence, etc.):

```
use Brick\Money\Currency;
use Superscript\Axiom\Money\Types\MinorMonetaryType;

$gbpType = new MinorMonetaryType(Currency::of('GBP'));

// Coerce from minor units (100 pence = £1.00)
$money = $gbpType->coerce(100)->unwrap()->unwrap();
// Result: Money object with GBP 1.00

// Coerce from string of minor units
$money = $gbpType->coerce('2550')->unwrap()->unwrap();
// Result: Money object with GBP 25.50
```

### Dynamic Monetary Type

[](#dynamic-monetary-type)

Automatically detect and parse currency from string:

```
use Superscript\Axiom\Money\Types\DynamicMonetaryType;

$dynamicType = new DynamicMonetaryType();

// Automatically detects currency
$money = $dynamicType->coerce('USD 100')->unwrap()->unwrap();
// Result: Money object with USD 100

$money = $dynamicType->coerce('€50.25')->unwrap()->unwrap();
// Result: Money object with EUR 50.25
```

### Money Operations

[](#money-operations)

Perform mathematical operations on Money objects:

```
use Brick\Money\Money;
use Superscript\Axiom\Money\Operators\MoneyOverloader;

$overloader = new MoneyOverloader();

$a = Money::of(100, 'EUR');
$b = Money::of(50, 'EUR');

// Addition
$sum = $overloader->evaluate($a, $b, '+');
// Result: EUR 150.00

// Subtraction
$diff = $overloader->evaluate($a, $b, '-');
// Result: EUR 50.00

// Multiplication (multiplies left by the amount from right)
$product = $overloader->evaluate($a, $b, '*');
// Result: EUR 5000.00 (100 * 50)

// Division (divides left by the amount from right)
$quotient = $overloader->evaluate($a, $b, '/');
// Result: EUR 2.00 (100 / 50)

// Comparisons
$isEqual = $overloader->evaluate($a, $b, '==');     // false
$isLess = $overloader->evaluate($b, $a, '');    // true
```

### Monetary Intervals

[](#monetary-intervals)

Work with ranges of monetary values:

```
use Brick\Money\Currency;
use Brick\Money\Money;
use Superscript\Axiom\Money\Types\MonetaryIntervalType;
use Superscript\MonetaryInterval\MonetaryInterval;
use Superscript\MonetaryInterval\IntervalNotation;

$intervalType = new MonetaryIntervalType(Currency::of('EUR'));

// Parse interval from string notation
$interval = $intervalType->coerce('[100,200]')->unwrap()->unwrap();
// Result: MonetaryInterval from EUR 100 to EUR 200 (inclusive)

// Create MonetaryInterval directly
$interval = new MonetaryInterval(
    left: Money::of(100, 'EUR'),
    right: Money::of(200, 'EUR'),
    notation: IntervalNotation::CLOSED
);

// Format interval
$formatted = $intervalType->format($interval);
// Result: "[EUR 100.00, EUR 200.00]"
```

### Monetary Interval Operations

[](#monetary-interval-operations)

```
use Superscript\Axiom\Money\Operators\MonetaryIntervalOverloader;

$overloader = new MonetaryIntervalOverloader();

$interval1 = new MonetaryInterval(
    left: Money::of(100, 'EUR'),
    right: Money::of(200, 'EUR'),
    notation: IntervalNotation::CLOSED
);

$interval2 = new MonetaryInterval(
    left: Money::of(150, 'EUR'),
    right: Money::of(250, 'EUR'),
    notation: IntervalNotation::CLOSED
);

// Check if intervals overlap
$overlaps = $overloader->evaluate($interval1, $interval2, '&&');
// Result: true (they overlap from EUR 150 to EUR 200)

// Union of intervals
$union = $overloader->evaluate($interval1, $interval2, '||');
// Result: MonetaryInterval from EUR 100 to EUR 250
```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Run all tests
composer test

# Run unit tests only
composer test:unit

# Run type checking
composer test:types

# Run mutation testing
composer test:infection
```

### Code Quality

[](#code-quality)

The project enforces 100% code coverage and uses:

- **PHPUnit**: Unit testing
- **PHPStan**: Static analysis
- **Laravel Pint**: Code style
- **Infection**: Mutation testing

### Linting

[](#linting)

```
vendor/bin/pint
```

Dependencies
------------

[](#dependencies)

This library builds on several excellent packages:

- [brick/money](https://github.com/brick/money): Robust money and currency library
- [gosuperscript/schema](https://github.com/gosuperscript/schema): Schema validation framework
- [superscript/interval](https://github.com/superscript/interval): Interval mathematics
- [superscript/monetary-interval](https://github.com/superscript/monetary-interval): Monetary interval support

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file for details.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate and maintain the existing code quality standards.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance83

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~47 days

Total

3

Last Release

87d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9832602d5b04f09fa5bd162acbaf87b0e5c50ce9a96b970424e78a3830695eb1?d=identicon)[robertvansteen](/maintainers/robertvansteen)

---

Top Contributors

[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (7 commits)")[![robertvansteen](https://avatars.githubusercontent.com/u/14931924?v=4)](https://github.com/robertvansteen "robertvansteen (6 commits)")[![fawazsuleiman](https://avatars.githubusercontent.com/u/129744165?v=4)](https://github.com/fawazsuleiman "fawazsuleiman (1 commits)")

---

Tags

schemavalidationmoneycurrencyintervalmonetary

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gosuperscript-schema-money/health.svg)

```
[![Health](https://phpackages.com/badges/gosuperscript-schema-money/health.svg)](https://phpackages.com/packages/gosuperscript-schema-money)
```

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64236.9M185](/packages/opis-json-schema)[romaricdrigon/metayaml

Using \[Yaml|Xml|json\] schemas files to validate \[Yaml|Xml|json\]

103306.5k8](/packages/romaricdrigon-metayaml)[evaisse/php-json-schema-generator

A JSON Schema Generator.

20298.5k1](/packages/evaisse-php-json-schema-generator)[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

288.2k](/packages/romegasoftware-laravel-schema-generator)

PHPackages © 2026

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