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

[BUGFIX] Create default Size with correct types in expandBackgroundShorthand #814

Merged
merged 2 commits into from
Jan 26, 2025

Conversation

oliverklee
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Jan 25, 2025

Coverage Status

coverage: 50.946%. remained the same
when pulling 06a7fad on bugfix/size-constructor-parameters
into 0c96d67 on main.

Copy link
Contributor

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

We need some unit tests here to help us mere mortals understand what is happening, and what is supposed to be happening.

Once we've established what's going on, and how the original code worked (or didn't), the changelog entry can be more descriptive.

@JakeQZ JakeQZ added the unit tests needed PRs with code changes lacking sufficient complementary tests label Jan 26, 2025
@oliverklee oliverklee force-pushed the bugfix/size-constructor-parameters branch from 36cfa29 to 0ada1ca Compare January 26, 2025 10:32
@oliverklee
Copy link
Contributor Author

I agree that we should cover bug fixes (including fixes to issues found by PHPStan) with unit tests (i.e., regression tests).

In this particular case, I'd prefer not to spend time on writing tests as the offending code is part of a deprecated method that we're planning to remove in #511. Would you be okay with not having regression tests in this case?

This code would break once we add native types to constructors (see #818).

I'm not quite happy with the commit and changelog messages either and would appreciate some help.

This is the called constructor:

function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0);

When constructing the Size instances, the offending code has an extraneous null argument before the $bIsColorComponent argument, which results in those constructor arguments:

  • $fSize = 0 (correct)
  • $sUnit = '%' (correct)
  • $bIsColorComponent = null (should be false)
  • $iLineNo = false (should be $this->iLineNo)
  • $this->iLineNo going to nothing (extraneous constructor argument)

So in effect (as long as we don't have native type for the Size constructor`), the line number gets lost.

What could be a more fitting commit and change logmessage for this?

@JakeQZ
Copy link
Contributor

JakeQZ commented Jan 26, 2025

In this particular case, I'd prefer not to spend time on writing tests as the offending code is part of a deprecated method that we're planning to remove in #511.

I hadn't relized this was in a deprecated method.

Would you be okay with not having regression tests in this case?

Yes, in this case.

When constructing the Size instances, the offending code has an extraneous null argument before the $bIsColorComponent argument, which results in ... the line number gets lost.

I think the line number being passed is not correct anyway, since it's that of the declaration block rather than the rule. Also, these are the default values for when background position is not specified, so perhaps it's right that no line number is set.

Thus it might be best to simply remove all the null/zero/false arguments (i.e. just have new Size(0, '%')), so that the behaviour is effectively unchanged (but the Size object will now be constructed with the correct/expected types).

What could be a more fitting commit and change logmessage for this?

Perhaps "Create default Size with correct types in expandBackgroundShorthand". But if this method is going to be removed anyway, and as it's already deprecated, perhaps it's best not to have a changelog entry - changes to deprecated methods aren't really relevant.

@oliverklee oliverklee changed the title [BUGFIX] Avoid nonsense argument for the Size constructor [BUGFIX] Create default Size with correct types in expandBackgroundShorthand Jan 26, 2025
@oliverklee oliverklee removed the unit tests needed PRs with code changes lacking sufficient complementary tests label Jan 26, 2025
@oliverklee oliverklee force-pushed the bugfix/size-constructor-parameters branch from 0ada1ca to 2a0fd11 Compare January 26, 2025 19:30
@oliverklee
Copy link
Contributor Author

Thanks! I've updated the commit message and PR title accordingly and removed the changelog entry. (For the backport PR, I think the changelog entry would still be helpful.)

@oliverklee oliverklee requested a review from JakeQZ January 26, 2025 19:30
Copy link
Contributor

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

I used the visual merge to resolve the conflict in phpstan-baseline.neon, which seems to have worked out OK.

Thus it might be best to simply remove all the null/zero/false arguments (i.e. just have new Size(0, '%')), so that the behaviour is effectively unchanged

I note you didn't adopt that suggestion, but as this is a deprecated method, it doesn't really matter.

(For the backport PR, I think the changelog entry would still be helpful.)

If we do a backport. But even then, the method is already deprecated in the 8.x branch.

@JakeQZ JakeQZ merged commit 59bcb6c into main Jan 26, 2025
21 checks passed
@JakeQZ JakeQZ deleted the bugfix/size-constructor-parameters branch January 26, 2025 23:46
oliverklee added a commit that referenced this pull request Jan 27, 2025
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.

3 participants