Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Clock] Return Symfony ClockInterface in ClockSensitiveTrait #53080

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

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Dec 14, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? no
Deprecations? no
Issues
License MIT

@nicolas-grekas I don't understand why the ClockSensitiveTrait::mockTime returns a PSR ClockInterface, instead of a Symfony ClockInterface. Is this done on purpose? Or was this a mistake?

@carsonbot carsonbot added this to the 6.4 milestone Dec 14, 2023
@ruudk ruudk marked this pull request as draft December 14, 2023 15:21
@alexandre-daubois
Copy link
Member

In the same idea, I'm not sure to clearly understand the convention in the code base on which class to use when one is available in Contracts, PSR and in the component itself (e.g. EventDispatcher)? 🤔

@carsonbot carsonbot changed the title Return Symfony ClockInterface in ClockSensitiveTrait [Clock] Return Symfony ClockInterface in ClockSensitiveTrait Dec 18, 2023
@nicolas-grekas
Copy link
Member

why the ClockSensitiveTrait::mockTime returns a PSR ClockInterface, instead of a Symfony ClockInterface

No specific reason I can think of...

In the same idea, I'm not sure to clearly understand the convention in the code base on which class to use when one is available in Contracts, PSR and in the component itself (e.g. EventDispatcher)? 🤔

See SOLID principles: use the most abstract interface when it fits your need. If you need a more capable interface, use the more capable one.

@stof
Copy link
Member

stof commented Dec 18, 2023

Anytime a component only needs the API of the PSR interface, we use that as parameter type as it makes the component usable with any PSR-20 implementation and not just symfony/clock

@alexandre-daubois
Copy link
Member

Got it, thank you both 👍

@nicolas-grekas
Copy link
Member

@ruudk please advise what you'd like to do with this PR. "Draft status" is blurry for OSS maintainers.

@ruudk ruudk marked this pull request as ready for review January 2, 2024 14:58
@ruudk
Copy link
Contributor Author

ruudk commented Jan 2, 2024

I made it Draft because I wasn't sure. So I made it ready for review now.

I think that the return type should be the thing that is going to be returned. That allows the developer, when using this in the test, to call withTimeZone on the returned Symfony Clock. Obviously, that already works, except that PHPStorm and PHPStan don't understand it.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

for 7.1 (this doesn't look like a bugfix to me)

@fabpot fabpot modified the milestones: 6.4, 7.1 Jan 6, 2024
I don't understand why the ClockSensitiveTrait::mockTime returns a PSR ClockInterface, instead of a Symfony ClockInterface.

Is this done on purpose? Or was this a mistake?
@fabpot fabpot changed the base branch from 6.4 to 7.1 January 6, 2024 14:53
@fabpot
Copy link
Member

fabpot commented Jan 6, 2024

Thank you @ruudk.

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.

8 participants