Repository navigation
Tidy up conversion and creation for 2.0 - #30
Merged
Merged
Conversation
toInt() dropped decimals without notice, the last call that did so. It now refuses a value with decimals other than zero unless a rounding mode is passed; ROUND_DOWN gives the old result. The range check runs on the rounded value, so a value that rounds past the integer range overflows. isBigInteger() is replaced by fitsInt(). The old name read as "is a large whole number" while it only looked at the range, and callers always negated it before toInt(). The value type is Stringable instead of object. Other objects were only turned away after the call; every class with __toString() is Stringable. create() returns a Decimal as is when no scale is passed. The object is immutable, so the copy served no purpose. truncate() goes through round() with ROUND_DOWN, with the same results as before, including that it never adds zeros.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #30 +/- ##
============================================
+ Coverage 95.59% 95.81% +0.22%
Complexity 201 201
============================================
Files 1 1
Lines 454 454
============================================
+ Hits 434 435 +1
+ Misses 20 19 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five API changes for 2.0, all on the conversion and creation side.
toInt()no longer drops decimals on its own. A value with decimals other than zero throws aRoundingNecessaryExceptionunless a rounding mode is passed:toInt(Decimal::ROUND_DOWN)gives the 1.x result. This was the last call that shortened a value without notice. The range check runs on the rounded value.isBigInteger()is replaced byfitsInt(), which answers the opposite question. The old name read as "is a large whole number" although it only checked the range, and callers negated it beforetoInt().Stringableinstead ofobject. Every class with__toString()isStringable, so valid input is unchanged; any other object is now aTypeErrorat the call.Decimal::create()returns aDecimalas is when no scale is passed. It returned a copy of an immutable object before.truncate()goes throughround()withROUND_DOWN. Results are unchanged, including that it never adds zeros.The upgrade guide covers the
toInt()change with a 1.x / 2.0 table, the object type and the removed method. cakephp-decimal uses none of the changed calls.