Skip to content

[4.x] Upgrade brick/math to support versions ^0.14–^0.17#638

Merged
ramsey merged 1 commit into
ramsey:4.xfrom
delolmo:brick-math-0.17-support
Apr 27, 2026
Merged

[4.x] Upgrade brick/math to support versions ^0.14–^0.17#638
ramsey merged 1 commit into
ramsey:4.xfrom
delolmo:brick-math-0.17-support

Conversation

@delolmo

@delolmo delolmo commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

I noticed there have been a few attempts at adding support for newer brick/math versions, so I wanted to take a stab at it with an approach that keeps full backward compatibility.

The main challenge is that brick/math 0.15 renamed the RoundingMode constants from UPPER_SNAKE_CASE to PascalCase and changed MathException from a class to an interface. Rather than dropping support for older versions, I introduced a small internal BrickMathRoundingMode class that resolves the correct constant at runtime using defined() with a fallback. It ain't pretty, but it works seamlessly across all versions.

I also tightened the PHPDoc types on CalculatorInterface to satisfy the stricter type annotations introduced in newer brick/math releases, and adjusted a couple of test assertions where error message wording changed.

The full composer test suite (lint, benchmarks, PHPStan, unit tests) passes on both sides of the 0.15 breaking-change boundary, and unit tests pass on every supported version: 0.8.16, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, and 0.17.

See #636.

Test plan

  • composer test passes with brick/math 0.14
  • composer test passes with brick/math 0.17
  • Unit tests pass across all 10 supported major versions (0.8.16 through 0.17)
  • CI passes with both locked and highest dependency strategies

Introduce BrickMathRoundingMode internal class to resolve
Brick\Math\RoundingMode constants across versions that use different
naming conventions (UPPER_SNAKE_CASE < 0.15, PascalCase >= 0.15).

Tighten PHPDoc types on CalculatorInterface to satisfy stricter
type annotations in newer brick/math releases. Update test assertions
for error messages that changed wording across versions.

Widen composer constraint to >=0.8.16 <=0.17.
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.13%. Comparing base (3d1c6d9) to head (4f04210).
⚠️ Report is 1 commits behind head on 4.x.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                4.x     #638      +/-   ##
============================================
+ Coverage     95.12%   95.13%   +0.01%     
- Complexity      575      576       +1     
============================================
  Files            70       71       +1     
  Lines          1640     1645       +5     
============================================
+ Hits           1560     1565       +5     
  Misses           80       80              
Files with missing lines Coverage Δ
src/Converter/Number/GenericNumberConverter.php 100.00% <ø> (ø)
src/Math/BrickMathCalculator.php 100.00% <100.00%> (ø)
src/Math/BrickMathRoundingMode.php 100.00% <100.00%> (ø)

@ramsey
ramsey merged commit 1a1f98b into ramsey:4.x Apr 27, 2026
36 checks passed
@delolmo
delolmo deleted the brick-math-0.17-support branch April 28, 2026 10:14
@miken32

miken32 commented May 15, 2026

Copy link
Copy Markdown

@ramsey this still needs a new release pushed out before it shows up on Packagist

@ahsankhatri

Copy link
Copy Markdown

@ramsey Thanks for merging this PR. Eagerly waiting for a new release :)

@aletundo

Copy link
Copy Markdown

@ramsey we are all on the same boat :D Any news for the release?

@neoighodaro

Copy link
Copy Markdown

Just checking in like the rest. Thanks in advance.

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.

6 participants