Skip to content

Add scalar math, named dimensions, and Doctrine integration#6

Merged
khaledalam merged 3 commits into
mainfrom
feature/scalar-dimensions-doctrine
Jul 10, 2026
Merged

Add scalar math, named dimensions, and Doctrine integration#6
khaledalam merged 3 commits into
mainfrom
feature/scalar-dimensions-doctrine

Conversation

@khaledalam

Copy link
Copy Markdown
Owner

Three utility features that round out the arithmetic and open a second framework ecosystem.

Added

  • Scalar math on Quantity: times(), dividedBy() (guards zero), pow() (dimension-aware, (2 m)² = 4 m²), sqrt() (halves the dimension, throws on odd dimensions / negatives), abs(), negate().
  • Named dimensionsQuantity::dimensionName() / Dimension::name() return "velocity", "force", "pressure", etc. (null when unrecognized). Plus Dimension::power() / Dimension::root().
  • Doctrine integrationKhaledAlam\Unit\Doctrine\QuantityType (DBAL ^4) persists a Quantity as a string column; works in Symfony and any Doctrine project (parallels the Laravel cast).

Changed

  • Dimension::__toString() emits unescaped Unicode so temperature reads as {"Θ":1}.

Verification

  • 100% coverage maintained — 9/9 classes, 59/59 methods, 368/368 lines (PCOV).
  • 94 tests, 367 assertions. PHPStan level max clean, CS-Fixer clean. New runnable examples/scalar-math.php.

@khaledalam khaledalam merged commit 8ec77c7 into main Jul 10, 2026
11 checks passed
@khaledalam khaledalam deleted the feature/scalar-dimensions-doctrine branch July 10, 2026 17:48
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