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

Mark method from abstract classes as final #2194

Merged

Conversation

jordisala1991
Copy link
Member

@jordisala1991 jordisala1991 commented Oct 31, 2021

Subject

I am targeting this branch, because this is BC.

This change will help with #2191 . There are methods on that PR that are not present on this one, so this PR only focuses on the finals that will be useful for the 4.x version (there is no need to mark something final that in 4.x is removed).

Changelog

### Changed
- Added final annotation to methods that will be final on 4.x.

@jordisala1991
Copy link
Member Author

Not sure what kind of label or changelog is needed for this change. @VincentLanglet wdyt?

@jordisala1991
Copy link
Member Author

I will take care of this merge to 4.x, it will be a mess but I can do it.

@jordisala1991 jordisala1991 requested a review from a team October 31, 2021 17:25
@phansys
Copy link
Member

phansys commented Oct 31, 2021

Not sure what kind of label or changelog is needed for this change. @VincentLanglet wdyt?

IMO, these changes require a MINOR release, and the changelog label should be "Changed", since these changes are marking existing methods as final.

phansys
phansys previously approved these changes Oct 31, 2021
@phansys
Copy link
Member

phansys commented Oct 31, 2021

Additionally, I think this PR also deserves an upgrade note, since these docblocks generate deprecation messages if these methods are overridden.

@jordisala1991
Copy link
Member Author

Additionally, I think this PR also deserves an upgrade note, since these docblocks generate deprecation messages if these methods are overridden.

Added.

core23
core23 previously requested changes Nov 1, 2021
@@ -62,51 +62,81 @@ public function __toString()
return $this->getName() ?? '-';
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

We should not do this for model classes because they are more likely to be customised and overridden.

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont know what kind of customization is needed for a getter and a setter, can you provide an example?

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, if some user needs to customize the methods, he can create a class from the Interfaces, no need to use this Model.

Copy link
Member

Choose a reason for hiding this comment

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

Or at least open an issue with an explanation of the needs, and we can still remove the final if we find it's justified.

It's easier to add final now because adding final is not BC but removing final is.

Copy link
Member

Choose a reason for hiding this comment

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

e.g. you want to update the updatedAt or enabled state when setting some property.

Also, if some user needs to customize the methods, he can create a class from the Interfaces, no need to use this Model.

Yes you could create some custom class, but that's not the idea of reusable models. With the same logic we could make the entity classes final.

Copy link
Member Author

@jordisala1991 jordisala1991 Nov 1, 2021

Choose a reason for hiding this comment

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

As @VincentLanglet said, what about making them final and if someone complains on a concrete use case, we can change it because it will be BC. For your example, using the prePersist could solve the issue (and if you really need to modify all the methods, you might as well create from the interface directly). wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

By the way we should make the decision consistent between the Classification and the Media bundle about entities

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO it should be as we did for any other final TBH, it is final until it can be proven that there is a real need that cannot be solved in other ways.

When checking for final, we should ensure we added it for classes and for abstract classes.

That being said, the more time we spend on this, the more we delay releases and working on other bundles...

Copy link
Member

Choose a reason for hiding this comment

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

IMO it should be as we did for any other final TBH, it is final until it can be proven that there is a real need that cannot be solved in other ways.

When checking for final, we should ensure we added it for classes and for abstract classes.

I agree

Copy link
Member

Choose a reason for hiding this comment

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

Still not a fan, but feel to merge this if I'm the only one with this considerations.

@jordisala1991 jordisala1991 requested a review from core23 November 2, 2021 07:01
@jordisala1991 jordisala1991 dismissed core23’s stale review November 2, 2021 18:38

Lets see if someone raises this concern before having to discard final keyword

@jordisala1991 jordisala1991 merged commit e0bd161 into sonata-project:3.x Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants