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

Cleanup dead setDefaultOptions(..) methods #6334

Merged
merged 1 commit into from
Aug 28, 2020

Conversation

dmaicher
Copy link
Contributor

Subject

While checking some of the phpstan errors on this PR I noticed some related to the non-existing OptionsResolverInterface.

So I propose here to cleanup this dead code to simplify maintenance a bit 😊

I don't see any way how this could be a BC break for anyone.

Those methods are not part of any contract and cannot be called anymore since Symfony\Component\OptionsResolver\OptionsResolverInterface does not even exist.

Or did I miss something?

Actually @franmomu also suggested to remove them here.

I am targeting this branch, because I believe this is BC.

Changelog

### Removed
- long time deprecated and unused `setDefaultOptions` methods using `Symfony\Component\OptionsResolver\OptionsResolverInterface`

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2020

Codecov Report

❗ No coverage uploaded for pull request base (3.x@51deb2d). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##             3.x    #6334   +/-   ##
======================================
  Coverage       ?   77.59%           
  Complexity     ?     2600           
======================================
  Files          ?      140           
  Lines          ?     7743           
  Branches       ?        0           
======================================
  Hits           ?     6008           
  Misses         ?     1735           
  Partials       ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51deb2d...f30e4b2. Read the comment docs.

@VincentLanglet
Copy link
Member

Removing a public method is always a BC-break.
Even if there is no reason for someone to using it...

@dmaicher
Copy link
Contributor Author

Removing a public method is always a BC-break.
Even if there is no reason for someone to using it...

Can you explain how this could be a BC break? In which scenario would this break anything?

@VincentLanglet
Copy link
Member

Removing a public method is always a BC-break.
Even if there is no reason for someone to using it...

Can you explain how this could be a BC break? In which scenario would this break anything?

Someone really crazy could have written in his code

$foo = new FormTypeFieldExtension([], []);
$foo->setDefaultOptions(...);

It's not because symfony doesn't use it anymore that we can be sure that no one use it.

@dmaicher
Copy link
Contributor Author

Removing a public method is always a BC-break.
Even if there is no reason for someone to using it...

Can you explain how this could be a BC break? In which scenario would this break anything?

Someone really crazy could have written in his code

$foo = new FormTypeFieldExtension([], []);
$foo->setDefaultOptions(...);

Doing a $foo->setDefaultOptions(...); call is literally impossible without a type error. Since the interface Symfony\Component\OptionsResolver\OptionsResolverInterface does not event exist anymore but its the typehint for the argument

@VincentLanglet
Copy link
Member

Oh ! Ok, I understand.

@wbloszyk
Copy link
Member

wbloszyk commented Aug 27, 2020

Technicly it is BC-break. AdminBundle require BlockBundle 3.x or 4.x. In 3.x in src/Resources/stubs/symfony2.php you can find Symfony\Component\OptionsResolver\OptionsResolverInterface.

It is not ower namespace and it is not support for Symfony so remove it is BC.

IMO we should remove it in BlockBundle 3.x too. We should not using not ower namespaces.

@dmaicher Can you do it for BlockBundle too?

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L135-L144
if (!$resolver instanceof OptionsResolver) { wil be always true and will throw BadMethodCallException

@dmaicher
Copy link
Contributor Author

IMO we should remove it in BlockBundle 3.x too. We should not using not ower namespaces.

@dmaicher Can you do it for BlockBundle too?

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L135-L144
if (!$resolver instanceof OptionsResolver) { wil be always true and will throw BadMethodCallException

Oh wow. That is an interesting "hack" on the BlockBundle.

Unfortunately there we cannot remove it yet I think.

There is this class: https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Util/OptionsResolver.php

Which is used on the bundle itself and will use the stub interface

@wbloszyk
Copy link
Member

wbloszyk commented Aug 27, 2020

@dmaicher
I didn't dig so much. You show me Sonata\BlockBundle\Util\OptionResolver. In my case it is Symfony\Component\OptionsResolver\OptionsResolver.

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L135-L144

@dmaicher
Copy link
Contributor Author

@dmaicher
I didn't dig so much. You show me Sonata\BlockBundle\Util\OptionResolver. In my case it is Symfony\Component\OptionsResolver\OptionsResolver.

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L135-L144

@wbloszyk but the instance passed to those setDefaultSettings methods is this one:

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/BlockContextManager.php#L240

So the methods are still called. Which means removing them would break BC for sure.

@wbloszyk
Copy link
Member

@dmaicher
I didn't dig so much. You show me Sonata\BlockBundle\Util\OptionResolver. In my case it is Symfony\Component\OptionsResolver\OptionsResolver.
https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L135-L144

@wbloszyk but the instance passed to those setDefaultSettings methods is this one:

https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/BlockContextManager.php#L240

So the methods are still called. Which means removing them would break BC for sure.

It is strange hack which is remove in 4.x. I think it is OK.

@dmaicher Thanks for check it.

@wbloszyk wbloszyk closed this Aug 28, 2020
@wbloszyk wbloszyk reopened this Aug 28, 2020
@wbloszyk wbloszyk merged commit 5ae2b30 into sonata-project:3.x Aug 28, 2020
@wbloszyk
Copy link
Member

Thanks @dmaicher

@dmaicher dmaicher deleted the remove_dead_code branch August 28, 2020 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants