Skip to content

[Console] introduce __toString method annotation to InputInterface #42056

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

Conversation

boesing
Copy link
Contributor

@boesing boesing commented Jul 11, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #42042
License MIT
Doc PR none yet, please ping me if this will be necessary

As a preparation for 6.0, we are adding __toString as method declaration. This avoids having BC-breaks in upstream projects as suggested by @wouterj.
In 6.0, the Stringable interface will be implemented instead.

Fixes #42042

If this feature will be accepted, I'm willing to create the PR for 6.0 which adds the Stringable interface. 👍🏼

As a preparation for 6.0, we are adding `__toString` as method declaration. This avoids having BC-breaks in upstream projects as suggested by @wouterj.
In 6.0, the `Stringable` interface will be implemented instead.

Fixes symfony#42042

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@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 5.4 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

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@nicolas-grekas nicolas-grekas added this to the 5.4 milestone Jul 11, 2021
@nicolas-grekas nicolas-grekas changed the title [Console] feature: introduce __toString method annotation to InputInterface [Console] introduce __toString method annotation to InputInterface Jul 11, 2021
@nicolas-grekas
Copy link
Member

Please add a changelog entry in the component.
It could also be useful to document what the method is supposed to return, because it's not obvious to me at least.

@boesing
Copy link
Contributor Author

boesing commented Jul 11, 2021

@nicolas-grekas 🤨 it already exists, I just added it to the interface. could you give me a little hint on how you expect that being documented?
Will create it afterwards.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 11, 2021

If we add the method, it means we're expect implementations to return something useful.
We should tell what kind of useful output is expected here.
You could take inspiration from what existing implementations do already I suppose.
I don't know (and I didn't had a look :) )

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing boesing force-pushed the feature/stringable-inputinterface branch from ef230ca to 7516c10 Compare July 12, 2021 17:52
boesing added 2 commits July 12, 2021 19:52
…when calling that method

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
…oString` method annotation

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
@boesing
Copy link
Contributor Author

boesing commented Jul 12, 2021

I've created a CHANGELOG entry as well as the method description.
If something is missing, please let me know.

@derrabus I've added the return type-hint to the newly created method within the test-asset.

@boesing boesing requested a review from derrabus July 12, 2021 17:54
@OskarStark
Copy link
Contributor

Could you please open a PR on the symfony/docs repo and add a test case? Thanks

@boesing
Copy link
Contributor Author

boesing commented Jul 13, 2021

So just to clarify so I understand the open TODOs:

I have added exactly zero new functionality here and there are existing unit tests for those __toString methods in current implementations. What kind of unit tests do you want me to create?

Regarding the docs - I will check that out tomorrow to see how this project is structured. Do you want me to add the description I've added to the interface to the documentation or do you have something specific in mind?

@@ -18,6 +18,9 @@
* InputInterface is the interface implemented by all input classes.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method string __toString() Returns a stringified representation of the args passed to the command.
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK if someone does not implement this method, a deprecation is thrown.

I would like to have a test case which asserts this deprecation (a missing implementation) and has the "@group legacy".

Not sure I missed sth.

Copy link
Contributor Author

@boesing boesing Jul 13, 2021

Choose a reason for hiding this comment

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

I'll see how to achieved that. Thanks for clarification.
The unit test to verify the deprecation should be part of the docs repo?

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Please also adjust UPGRADE-5.4.md and UPGRADE-6.0.md. If we introduce a deprecation, it must be documented there.

@@ -5,6 +5,7 @@ CHANGELOG
---

* Add `TesterTrait::assertCommandIsSuccessful()` to test command
* Add `InputInterface::__toString()` method annotation. This will be replaced by the extension of the `Stringable` interface in 6.0.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Add `InputInterface::__toString()` method annotation. This will be replaced by the extension of the `Stringable` interface in 6.0.
* Add method `__toString()` to `InputInterface`

@nicolas-grekas
Copy link
Member

Friendly ping @boesing

@boesing
Copy link
Contributor Author

boesing commented Sep 8, 2021

Thanks for pinging me, @nicolas-grekas
I dont think I will work more on this because of the following reason:

  1. I dont really need the feature that much that I want to work on multiple repositories to add a method which is already present in almost all implementations
  2. I have plenty of open work to do in another framework to be ready for PHP 8.1 and thus the amount of time is very limited
  3. I dont get what unit test has to be created to cover the deprecation/legacy group stuff requested by @OskarStark

so in the end, the amount of work I have to put into this is not aligned with the benefit of the outcome. Thank you all for the guiding, sorry if I wasted your time with this.

@boesing boesing closed this Sep 8, 2021
@stof
Copy link
Member

stof commented Sep 8, 2021

@boesing writing a unit test that pass a Input implementation without __toString to the Application, and expecting a deprecation message.

@derrabus
Copy link
Member

derrabus commented Sep 8, 2021

@OskarStark Do you have time to take over?

chalasr added a commit that referenced this pull request Dec 21, 2021
…` (boesing)

This PR was merged into the 6.1 branch.

Discussion
----------

[Console] Add method `__toString()` to `InputInterface`

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #42042
| License       | MIT
| Doc PR        | -

Continues #42056. No test added because adding one for the deprecation feels like testing DebugClassLoader, which is not the point here.

Commits
-------

224f3e3 [Console] Add method `__toString()` to `InputInterface`
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.

[Console] InputInterface extends Stringable
6 participants