$ show brick/money
Brick\Money is a high-quality, immutable PHP library for representing monetary values, performing arithmetic, currency conversion, allocation, and locale-aware formatting. It provides exact arithmetic via brick/math, supports multiple contexts (default, cash rounding, custom scale, auto-scale), and includes a rich set of exchange rate providers (configurable, PDO-backed, cached, chained, base-currency derived). The library features a strategy pattern for allocation (five algorithms including Hamilton's method) and cross-currency comparison. It is thoroughly tested, type-safe, and follows modern PHP practices (PHP 8.2+, readonly classes, enums, sealed interfaces). The codebase demonstrates strong software craftsmanship with clean abstractions, immutable value objects, and well-isolated components. It is actively maintained with regular releases and comprehensive documentation.
The LLM identified 3 files worth highlighting for reuse:
Implements the Hamilton method (largest remainder) for proportional allocation of a monetary amount among ratios. Self-contained, depends only on BigInteger and the AllocationStrategy interface. The algorithm computes floor amounts, then distributes the remainder step by step to allocatees with the largest fractional remainders. This is a non-obvious algorithm commonly needed in financial applications (e.g., tax distribution) and can be extracted and reused in any allocation context.
A fluent builder for constructing PdoProvider instances. Encapsulates the complex configuration of source/target currency selectors, dimension bindings, static conditions, ORDER BY clauses, and numeric currency code mode. Validates configuration at build time, preventing invalid states. This builder pattern is a reusable approach for constructing complex database-backed exchange rate providers and can be adapted to other providers.
Formats Money objects to locale-specific strings using ICU's number skeleton syntax. Handles currency display modes (Symbol, NarrowSymbol, Code, Name, None), hide-fraction-if-whole, custom currencies (non-ISO codes), and validates float accuracy to prevent silent precision loss. Performs locale validation to avoid ICU's silent fallback to process default. This formatter is a reusable component for any PHP library requiring locale-aware currency formatting with robust error handling.