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

Filter for arithmetic operations #28 #29

Open
wants to merge 42 commits into
base: 2.12.x
Choose a base branch
from
Open

Conversation

fgsl
Copy link

@fgsl fgsl commented Jul 13, 2021

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

I created this filter for an application that converts values from APIs. It's useful for measure unit conversions and making adjustments. For example, an endpoint returns the amount of RAM requested by an user and you can add a security margin.

fgsl added 2 commits July 14, 2021 07:55
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@fgsl fgsl closed this Jul 14, 2021
@fgsl fgsl reopened this Jul 14, 2021
@fgsl fgsl closed this Jul 14, 2021
@fgsl fgsl reopened this Jul 14, 2021
@boesing
Copy link
Member

boesing commented Jul 14, 2021

No worries, there is no way to let you fix the codestyle.
Ignore it for now, its a known issue with running coding-standard v1 on PHP 7.4.

@boesing boesing linked an issue Jul 14, 2021 that may be closed by this pull request
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@fgsl
Copy link
Author

fgsl commented Jul 14, 2021

No worries, there is no way to let you fix the codestyle.
Ignore it for now, its a known issue with running coding-standard v1 on PHP 7.4.

Thank you and excuse me. I thought I must format the code again and sent a new change...

Copy link
Member

@froschdesign froschdesign left a comment

Choose a reason for hiding this comment

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

We definitely need some documentation that shows real use cases for this filter.

src/FourOperations.php Outdated Show resolved Hide resolved
src/FourOperations.php Outdated Show resolved Hide resolved
test/FourOperationsTest.php Outdated Show resolved Hide resolved
test/FourOperationsTest.php Outdated Show resolved Hide resolved
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@fgsl fgsl closed this Jul 15, 2021
@fgsl fgsl reopened this Jul 15, 2021
@fgsl fgsl closed this Jul 15, 2021
@fgsl fgsl reopened this Jul 15, 2021
@fgsl fgsl requested a review from froschdesign July 15, 2021 12:54
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@fgsl fgsl closed this Jul 15, 2021
@fgsl fgsl reopened this Jul 15, 2021
@fgsl
Copy link
Author

fgsl commented Jul 15, 2021

I made a little change on typing, but I don't know I had to follow all the messages in https://github.com/laminas/laminas-filter/actions/runs/1033956242. I think some parameters must be mixed, because they can be integers or floats.

dependabot bot and others added 6 commits August 9, 2021 20:48
Bumps [pear/archive_tar](https://github.com/pear/Archive_Tar) from 1.4.13 to 1.4.14.
- [Release notes](https://github.com/pear/Archive_Tar/releases)
- [Commits](pear/Archive_Tar@1.4.13...1.4.14)

---
updated-dependencies:
- dependency-name: pear/archive_tar
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Bert Van Hauwaert <[email protected]>
Signed-off-by: Bert Van Hauwaert <[email protected]>
Signed-off-by: Bert Van Hauwaert <[email protected]>
Signed-off-by: Bert Van Hauwaert <[email protected]>
Signed-off-by: Bert Van Hauwaert <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@fgsl
Copy link
Author

fgsl commented Oct 25, 2021

Hi, @Ocramius. I have splitted the new filter into five filters, according your guideline.

@fgsl fgsl requested a review from Ocramius November 5, 2021 23:03
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

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

First, this needs to be rebased against the current release branch (currently 2.13.x, but likely to become 2.14.x later today when the PHP 8.1 support is merged); there are a few artifacts in here that seem to be from already merged changes (specifically the AllowList and DenyList implementations and tests).

Second, I've noted a number of areas where the behavior of the filters would not behave as expected when using integer values and operands. These likely need to be split into additional filters to allow both integer and float operations (with the exception of the Div filter, where a float is always expected).

src/Add.php Outdated
Comment on lines 20 to 21
$value = (float) $value;
$operand = (float) $this->options['operand'];
Copy link
Member

Choose a reason for hiding this comment

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

Why the cast to float here?

If I were operating on integers, I'd expect an integer return value. Perhaps this should be broken into "AddInteger" and "AddFloat"?

src/Sub.php Outdated
Comment on lines 20 to 21
$value = (float) $value;
$operand = (float) $this->options['operand'];
Copy link
Member

Choose a reason for hiding this comment

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

Same remark as for the Add filter; should this maybe be broken into SubInt and SubFloat?

Comment on lines +20 to +22
$value = (float) $value;
$operand = (float) $this->options['operand'];
return ($value % $operand);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't do what you think it does. From the manual:

Operands of modulo are converted to int before processing. For floating-point modulo, see fmod().

In other words, using the % operator will always return an integer. If you want to work with floats, you need to use fmod(). So, perhaps two variants, Mod and FloatMod, are needed.

src/Mul.php Outdated
Comment on lines 20 to 22
$value = (float) $value;
$operand = (float) $this->options['operand'];
return ($value * $operand);
Copy link
Member

Choose a reason for hiding this comment

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

Same remark as for Add and Sub: if integers are used, I'd expect an integer return value, not casting to float.

Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
Signed-off-by: Flávio Gomes da Silva Lisboa <[email protected]>
@Ocramius Ocramius removed their request for review February 15, 2022 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter for arithmetic operations
8 participants