8000 [Console] Remove redundant method getSaturation() by ivanpepelko · Pull Request #50317 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Remove redundant method getSaturation() #50317

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

Closed
wants to merge 0 commits into from

Conversation

ivanpepelko
Copy link
Contributor
@ivanpepelko ivanpepelko commented May 14, 2023
Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets none
License MIT
Doc PR none
  1. in getSaturation(), $diff is compared against int zero. This will only yield true when RGB values contain min/max color value (0 or 255). It will be always false for floats.
  2. in degradeHexColorToAnsi4() value returned from getSaturation() is rounded, which returns float, thus making comparison to int zero useless.
  3. in the same method, bitwise operations (final return statement) will convert number to int anyway, so the explicit cast was removed

In conclusion, getSaturation is redundant. Tests are expanded to show that even in min/max cases everything works fine.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.3 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Copy link
Contributor
@maxbeckers maxbeckers left a comment

Choose a reason for hiding this comment

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

LGTM

@fabpot
Copy link
Member
fabpot commented May 15, 2023

Merging in 6.3 as this is not a bug fix, but mainly an improvement.

@fabpot fabpot modified the milestones: 6.2, 6.3 May 15, 2023
@fabpot fabpot changed the base branch from 6.2 to 6.3 May 15, 2023 08:49
@fabpot
Copy link
Member
fabpot commented May 15, 2023

Thank you @ivanpepelko.

fabpot added a commit that referenced this pull request May 15, 2023
…epelko)

This PR was submitted for the 6.2 branch but it was merged into the 6.3 branch instead.

Discussion
----------

[Console] Remove redundant method getSaturation()

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | none
| License       | MIT
| Doc PR        | none

1. in `getSaturation()`, `$diff` is compared against `int` zero. This will only yield `true` when RGB values contain min/max color value (`0` or `255`). It will be always `false` for floats.
2. in `degradeHexColorToAnsi4()` value returned from `getSaturation()` is `round`ed, which returns float, thus making comparison to `int` zero useless.
3. in the same method, bitwise operations (final `return` statement) will convert number to `int` anyway, so the explicit cast was removed

In conclusion, `getSaturation` is redundant. Tests are expanded to show that even in min/max cases everything works fine.

Commits
-------

38021b5 [Console] Remove redundant method getSaturation()
@fabpot fabpot closed this May 15, 2023
@downhiller
Copy link

I think the main issue was a bug on line 167:

return (int) $diff * 100 / $v;

should have been

return (int) ($diff * 100 / $v);

$diff was always less between 0.0 and 1.0, so would always (int) to 0, or 1.

My contribution feels a bit redundant given that they've moved on and refactored a while back, but might help someone wondering why getSaturation doesn't return anything useful.

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.

7 participants
0