Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to convert a type to a floating point #42

Merged
merged 6 commits into from
Oct 31, 2024
Merged

Conversation

Baptouuuu
Copy link
Member

@Baptouuuu Baptouuuu commented Oct 31, 2024

Context

Initially Formal didn't support floats to prevent people to use this type to store data in an unsafe way (like money for example), due to multiple bugs that may arise.

But in some cases we do need to store values as floats. For example one may want to duplicate a value to an approximation and allow to search on this approximation.

One of these cases would be a system where you let users input any float value and store it as a string so the value never changes and duplicate this property as a decimal to only support search up to a certain decimal part.

Solution

Allow Formal\ORM\Definition\Type to handle the float type.

Notes

No Formal\ORM\Definition\Type\FloatType is created to prevent introducing implicits in converting the floats from the storage level.

This forces users to create their own type and know which type to use in the storage.

Bugs born out of implicits can't be universally fixed by an abstraction, it's up to each app to handle them.


Even though the diff is small this will be released as a new major version since technically it's a BC break.

@Baptouuuu Baptouuuu added the enhancement New feature or request label Oct 31, 2024
@Baptouuuu Baptouuuu self-assigned this Oct 31, 2024
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.22%. Comparing base (0b1ed42) to head (020b51e).
Report is 8 commits behind head on develop.

Files with missing lines Patch % Lines
src/Definition/Type/IntType.php 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop      #42   +/-   ##
==========================================
  Coverage      97.21%   97.22%           
  Complexity       637      637           
==========================================
  Files             96       96           
  Lines           4351     4359    +8     
==========================================
+ Hits            4230     4238    +8     
  Misses           121      121           

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

@Baptouuuu Baptouuuu marked this pull request as ready for review October 31, 2024 14:40
@Baptouuuu Baptouuuu merged commit 756f6fe into develop Oct 31, 2024
18 of 19 checks passed
@Baptouuuu Baptouuuu deleted the add-float-support branch October 31, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant