Skip to content

Add string parsing, humanize(), many unit families, and Laravel integration#4

Merged
khaledalam merged 5 commits into
mainfrom
feature/units-parse-humanize-laravel
Jul 10, 2026
Merged

Add string parsing, humanize(), many unit families, and Laravel integration#4
khaledalam merged 5 commits into
mainfrom
feature/units-parse-humanize-laravel

Conversation

@khaledalam

Copy link
Copy Markdown
Owner

Builds out the four most-requested capabilities to make the library more useful and broaden its reach.

Added

  • String parsingQuantity::parse('100 km/h'), Quantity::parse('-40 °C'), and multi-segment Quantity::parse('5 ft 3 in') (same-dimension segments are summed).
  • Quantity::humanize() — auto-selects the most readable unit via curated ladders (1500 m1.5 km, 2_500_000 B2.5 MB), leaving affine temperature units untouched.
  • Many more unit families — speed, data (decimal + binary), force, energy, power, pressure, frequency, angle, plus more length/mass/time/area/volume units. All verified against known reference values.
  • Laravel integration — auto-discovered UnitServiceProvider and an Eloquent AsQuantity cast (store a quantity in one column, get a Quantity back; strings are parsed on write). Custom units via config/unit.php.

Notes

  • illuminate/database added to require-dev (+ suggest); the Laravel test skips cleanly when it's absent.
  • PHPStan stays at level max, clean; the extended dimension model (data B, angle A) is fully typed.

Verification

  • 21/21 tests pass (incl. Eloquent cast round-trip), PHPStan max clean, CS-Fixer clean.
  • Live demo (docs/) extended with all new families; conversion math cross-checked against the PHP library.

@khaledalam khaledalam merged commit c36b07c into main Jul 10, 2026
11 checks passed
@khaledalam khaledalam deleted the feature/units-parse-humanize-laravel branch July 10, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant