Skip to content

Extension points

phil/tax

The library is plain PHP: it declares no service and no port, and its classes are final. It computes and itemises; which rates apply is the application's, and reaches the library as arguments.

PointHow
Which rates applyThe list given to MultiRateTaxCalculator::calculate() or extract(): a resolver of the application's own, from configuration or an external tax engine, builds it with TaxRate::of() or TaxRate::ofPercent() — see Choosing the rates
Taxes an engine already computedTaxLine::reported() keeps an amount as it was given; lines are gathered by TaxBreakdown::of(): the breakdown checks they share one base and keeps them without recomputing
Credit notesTaxBreakdown::reversed() negates every line exactly, whatever produced it
Catching the library's errorsEvery exception implements Phil\Tax\Exception\TaxException: one catch covers InvalidTaxRate, InvalidBreakdown and UntaxableBase

The rounding — half away from zero, per line — is the library's contract and is not replaced: a jurisdiction that rounds otherwise reports its lines computed elsewhere.