Skip to content

Conversation

@vlakoff
Copy link
Contributor

@vlakoff vlakoff commented Nov 16, 2025

This PR addresses issue #131.

In PHP 8.1+, implicit float-to-int conversion raises precision loss warnings. The current implementation in MaskUtil.php:

$fixedPercentVariances = (int) (abs($darkRatio - 0.5) * 20);

produces warnings when the result is a non-integer float (e.g., 19.666...).

The QR code specification requires explicit truncation at this step. This PR replaces the cast-only approach with floor() to ensure correct behavior and avoid precision loss warnings:

$fixedPercentVariances = (int) floor(abs($darkRatio - 0.5) * 20);

This change makes truncation explicit, aligns with the specification, and removes PHP 8.1+ warnings.

PHP 8.1 introduced warnings for implicit float-to-int conversions when precision is lost.
Using floor() makes truncation explicit, aligns with the QR code specification, and removes these warnings.
@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.81%. Comparing base (38d3c55) to head (8ad2573).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #211   +/-   ##
=========================================
  Coverage     70.81%   70.81%           
  Complexity      994      994           
=========================================
  Files            49       49           
  Lines          3169     3169           
=========================================
  Hits           2244     2244           
  Misses          925      925           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 16, 2025

By the way, this code path doesn’t appear to be covered by unit tests, since the tests didn’t flag the issue.

@DASPRiD
Copy link
Member

DASPRiD commented Nov 16, 2025

LGTM! And yeah, we don't have 100% code coverage, only the critical code paths are covered.

@DASPRiD DASPRiD merged commit 5278045 into Bacon:main Nov 16, 2025
9 checks passed
@vlakoff vlakoff deleted the fix/maskutil-floor branch November 17, 2025 22:06
@TimWolla
Copy link

I'm confused by this change. The explicit (int) cast will not emit a warning with or without a floor().

https://3v4l.org/OM0LP#veol

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 28, 2025

Thank you for pointing this out. You seem to be right — now I’m puzzled as well.

(That being said, the explicit floor may still be nice for code clarity.)

Issue #131 was encountered on the old version 1.0.2 — see line 223 at that time:

$intermediate = (BitUtils::unsignedRightShift($y, 1) + ($x / 3)) & 0x1;

(I had already done some “history digging” when figuring out #131, but I don’t know how I ended up on an unrelated line.)

@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 28, 2025

I've fed the code of MaskUtil::getDataMaskBit() into my AI slave, and it yelled a lot of warnings at me. This function definitely needs some reviewing.

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.

3 participants