Skip to content

refactor(bcmath): 浮動小数点演算をbcmath関数に置換#6557

Open
nanasess wants to merge 6 commits intoEC-CUBE:4.3-symfony7from
nanasess:refactor/bcmath-functions
Open

refactor(bcmath): 浮動小数点演算をbcmath関数に置換#6557
nanasess wants to merge 6 commits intoEC-CUBE:4.3-symfony7from
nanasess:refactor/bcmath-functions

Conversation

@nanasess
Copy link
Contributor

@nanasess nanasess commented Jan 5, 2026

概要(Overview・Refs Issue)

金額・ポイント・数量の計算処理において、浮動小数点演算の精度問題を回避するためbcmath関数を使用するよう修正しました。

対象ファイル:

  • PointProcessor: ポイント比較・加算にbccomp/bcaddを使用
  • OrderStateMachine: ポイント加算・減算にbcadd/bcsubを使用
  • DeliveryController: 支払条件の計算にbcsub/bcaddを使用
  • CartController: カート数量の合計にbcaddを使用、金額計算にbcsub/bcaddを使用
  • OrderType: 支払金額の比較にbccompを使用
  • ShippingMultipleController: 数量集計にbcaddを使用(4箇所)、引数に(string)キャスト追加
  • AdminController: 売上集計にbcaddを使用、引数に(string)キャスト追加
  • DeliveryFeeFreeByShippingPreprocessor: 送料無料判定にbcadd/bcmulを使用
  • StockDiffProcessor: 在庫数量集計にbcaddを使用、getDiffOfQuantitiesにbcsub/bcmulを使用
  • ShippingMultipleItemType: 数量集計にbcaddを使用
  • EntryController: カート数量集計にbcaddを使用
  • PurchaseFlow: reduce()内の冗長なキャストを削除

方針(Policy)

PHPの浮動小数点演算では精度の問題が発生する可能性があります。金額やポイントなど正確な計算が必要な箇所でbcmath関数を使用することで、この問題を回避します。

既存のコードで // @phpstan-ignore-line TODO bcmath-polyfill を使用する というコメントがあった箇所を中心に修正しています。

実装に関する補足(Appendix)

bcmath関数の使用方法:

  • bccomp($a, $b): 比較(戻り値: -1, 0, 1)
  • bcadd($a, $b): 加算
  • bcsub($a, $b): 減算
  • bcmul($a, $b): 乗算

コミット履歴

  1. 7b305b928a - refactor(bcmath): 浮動小数点演算をbcmath関数に置換
  2. 3fc19f2c10 - refactor(bcmath): 追加の浮動小数点演算をbcmath関数に置換
  3. 4903f18a05 - refactor(bcmath): getDiffOfQuantities等の追加bcmath対応とphp-cs-fixer/rector適用

テスト(Test)

  • 既存のユニットテストで動作確認

相談(Discussion)

特になし

マイナーバージョン互換性保持のための制限事項チェックリスト

  • 既存機能の仕様変更はありません
  • フックポイントの呼び出しタイミングの変更はありません
  • フックポイントのパラメータの削除・データ型の変更はありません
  • twigファイルに渡しているパラメータの削除・データ型の変更はありません
  • Serviceクラスの公開関数の、引数の削除・データ型の変更はありません
  • 入出力ファイル(CSVなど)のフォーマット変更はありません

🤖 Generated with Claude Code

金額・ポイント・数量の計算処理において、浮動小数点演算の精度問題を
回避するためbcmath関数を使用するよう修正。

- PointProcessor: ポイント比較・加算にbccomp/bcaddを使用
- OrderStateMachine: ポイント加算・減算にbcadd/bcsubを使用
- DeliveryController: 支払条件の計算にbcsub/bcaddを使用
- CartController: カート数量の合計にbcaddを使用
- OrderType: 支払金額の比較にbccompを使用

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dotani1111 dotani1111 added this to the 4.4.0 milestone Jan 7, 2026
@dotani1111 dotani1111 added improvement 機能改善 refactor リファクタリング labels Jan 7, 2026
nanasess and others added 5 commits January 9, 2026 17:54
以下のファイルで数量・金額計算をbcmath関数に変更:
- ShippingMultipleController: bcadd を使用(4箇所)
- AdminController: bcadd を使用(売上集計)
- DeliveryFeeFreeByShippingPreprocessor: bcadd/bcmul を使用
- StockDiffProcessor: bcadd を使用
- ShippingMultipleItemType: bcadd を使用
- EntryController: bcadd を使用

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- StockDiffProcessor: getDiffOfQuantitiesの演算をbcsub/bcmulに置換
- StockDiffProcessor: getQuantityByProductClassのPHPDoc型を修正
- AdminController: getPaymentTotal()に(string)キャスト追加
- CartController: 金額計算をbcsub/bcaddに置換
- ShippingMultipleController: bcadd引数に(string)キャスト追加
- PointProcessor: getTotal()の冗長な(string)キャストを削除
- PurchaseFlow: reduce内の冗長な(string)キャストを削除

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
bcadd()はstringを返すため、返り値の型宣言をintからstringに変更

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.29%. Comparing base (3c4c246) to head (179d0e9).
⚠️ Report is 1 commits behind head on 4.3-symfony7.

Files with missing lines Patch % Lines
...c/Eccube/Controller/ShippingMultipleController.php 75.00% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           4.3-symfony7    #6557      +/-   ##
================================================
- Coverage         82.33%   82.29%   -0.04%     
================================================
  Files               482      482              
  Lines             25691    25691              
================================================
- Hits              21152    21142      -10     
- Misses             4539     4549      +10     
Flag Coverage Δ
E2E 82.29% <97.36%> (-0.04%) ⬇️
Unit 82.29% <97.36%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement 機能改善 refactor リファクタリング

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants