magento / magento2-page-builder

Magento2 PageBuilder
Other
80 stars 62 forks source link

"Magento\PageBuilder\Plugin\Filter\TemplatePlugin" mismatching strict type #504

Closed Serializator closed 4 years ago

Serializator commented 4 years ago

Preconditions (*)

  1. Magento 2.3.5-p1
  2. Page Builder

Steps to reproduce (*)

Invoke Magento\Framework\Filter\Template->filter(...) with null as value

Expected result (*)

An empty string, at least not a type error if strict types aren't used for the invoked method

Actual result (*)

TypeError: Uncaught exception 'TypeError' with message 'Argument 2 passed to Magento\PageBuilder\Plugin\Filter\TemplatePlugin::afterFilter() must be of the type string, null given, called in .../vendor/magento/framework/Interception/Interceptor.php on line 146' in .../vendor/magento/module-page-builder/Plugin/Filter/TemplatePlugin.php:71

Cause

It is caused by the Magento\PageBuilder\Plugin\Filter\TemplatePlugin which uses strict types in the after plugin which does not match with any strict types on the original method.


It's kinda a double-edged sword. I think this is a bug because a plugin should match the arguments of the method which it is bound to, on the other side it isn't really a bug as much as not checking the data you pass before invocation.

PHPDocs clearly state that the argument should be a string, which is then in-directly enforced by the strict type in the plugin.

What I rather see is that this type is strictly enforced by the method itself directly, but that would be a backwards incompatible change (and the class is annotated with @api).

If you think this isn't a bug and should be closed because it should be the the responsibility of the developer to check their stuff, I kinda agree actually 😉

m2-assistant[bot] commented 4 years ago

Hi @Serializator. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


lbajsarowicz commented 4 years ago

@Serializator if you have access to page builder repository, please move issue there. Otherwise, I'll ask someone from the Magento community engineering to move it there

Serializator commented 4 years ago

@lbajsarowicz, I don't have access to that repository

lbajsarowicz commented 4 years ago

@tkacheva Could you move the issue to PageBuilder repository, please?

m2-assistant[bot] commented 4 years ago

Hi @engcom-Alfa. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Alfa commented 4 years ago

@sdzhepa Could you move this issue to the PageBuilder repo? Thanks!

bluemwhitew commented 4 years ago

The bot is trolling... 😑

bluemwhitew commented 4 years ago

Attempted to fix this as suggested, but ran into issues where this method is called elsewhere.

I would recommend re-raising this issue in the Magento 2 repository with a view to implementing strict types on the original method.

bluemwhitew commented 4 years ago

Are we able to move this issue back to the Magento 2 repository as above?

/cc @nizarn @omiroshnichenko

sdzhepa commented 4 years ago

fyi: @omiroshnichenko @bluemwhitew @nizarn

Due to not possible to transfer issue from private repo to public I have re-created new issue :

I think this one report in PB repo can be closed