Skip to content

Allow brick math 0.15 and 0.16#633

Closed
BackEndTea wants to merge 4 commits intoramsey:4.xfrom
BackEndTea:brick-math
Closed

Allow brick math 0.15 and 0.16#633
BackEndTea wants to merge 4 commits intoramsey:4.xfrom
BackEndTea:brick-math

Conversation

@BackEndTea
Copy link
Copy Markdown
Contributor

0.15 removed the 'old' rounding mode constants, so this includes a BC layer in the BrickMathCalculator

Description

This MR allows installation of brick math versions 0.15 and 0.16.

0.14 changed the rounding mode to an enum, but kept backwards compatability. in 0.15 this BC layer was removed.

To support older brick/math versions (and older PHP versions), we introduce a BC layer in the BrickMathCalculator class.

Motivation and context

How has this been tested?

I have ran the phpunit tests with brick/math 0.14, 0.15 and 0.16.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.

PHPUnit test are working for this MR, but there are some PHPStan failures. I'm not sure how to move forward with those.

0.15 removed the 'old' rounding mode constants, so this includes a BC layer in the `BrickMathCalculator`
@balu-lt
Copy link
Copy Markdown

balu-lt commented Mar 12, 2026

After creating PR #634 for the 5.x branch, I noticed you had already opened this PR for the 4.x branch.

By the way, is there an ETA for the v5 release?

Comment thread tests/Builder/FallbackBuilderTest.php Outdated

$fallbackBuilder->build($codec, $bytes);
}
// public function testBuildThrowsExceptionAfterAllConfiguredBuildersHaveErrored(): void
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these tests commented out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, i think i commented them out to debug something. It should be fine to uncomment them again

@ramsey
Copy link
Copy Markdown
Owner

ramsey commented Apr 15, 2026

It looks like brick/math broke a lot of BC with earlier releases and removed or moved a lot of things. That's why there are so many PHPStan errors. Is that something you're able to help clean up?

@BackEndTea
Copy link
Copy Markdown
Contributor Author

It looks like brick/math broke a lot of BC with earlier releases and removed or moved a lot of things. That's why there are so many PHPStan errors. Is that something you're able to help clean up?

No problem. My suggestion would be to 'simply' add a bunch of @phpstan-ignore comments to the errors that are due to the BC layer.

I think the most maintainable solution for this library is to get this MR (or another with a BC layer) merged and tagged.
Then in the next tag remove the BC layer again, and require a higher version of brick/match.

This would give users of the package an easier upgrade path, as this can be upgraded first, and then brick/math later. But it would introduce the least strain on maintainability.

Is that a solution that works for you?

These should be safe to remove when the BC layer is removed again
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 58.62069% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.48%. Comparing base (3d1c6d9) to head (bdcd9cb).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Math/BrickMathCalculator.php 58.62% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                4.x     #633      +/-   ##
============================================
- Coverage     95.12%   94.48%   -0.64%     
- Complexity      575      578       +3     
============================================
  Files            70       70              
  Lines          1640     1668      +28     
============================================
+ Hits           1560     1576      +16     
- Misses           80       92      +12     
Files with missing lines Coverage Δ
src/Math/BrickMathCalculator.php 83.56% <58.62%> (-16.44%) ⬇️

@BackEndTea
Copy link
Copy Markdown
Contributor Author

I have added the ignores, and made an example of dropping the BC layer again and requiring the newer brick math versions: BackEndTea#1

*/
final class BrickMathCalculator implements CalculatorInterface
{
private const ROUNDING_MODE_MAP = [
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    private const ROUNDING_MODE_MAP = [
        RoundingMode::UNNECESSARY => BrickMathRounding::Unnecessary ?? BrickMathRounding::UNNECESSARY,
        ...

Alternatively and a matter of taste, but this could also work instead of the static $roundingModeMap.
With this approach, you don't need defined(). The whole compat layer would be these 10 lines.

@jnoordsij
Copy link
Copy Markdown

With #638 merged I guess this is now obsolete?

@BackEndTea BackEndTea closed this May 7, 2026
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.

5 participants