modularity icon indicating copy to clipboard operation
modularity copied to clipboard

[Bug]: file_get_contents in LibraryProperties triggers WP Plugin Check

Open Biont opened this issue 6 months ago • 1 comments

Description of the bug

This is a "bug" more in the way of an "annoyance" rather than a problem with the code.

When a plugin is tested against the official Plugin Check utility, one of the warnings/errors will be that we're supposed to use wp_remote_get instead of file_get_contents. This is clearly a false-positive since we are not making an HTTP call.

There has been an attempt to make the behaviour of the sniff a little smarter to check for a few obvious "local usage scenarios", but our usage here still causes the warning.

It seems we have 2 options:

  • Try to trigger the "local usage detection" somehow. Judging from the code, the only real option is to pass $use_include_path = true, but I am not sure we want that
  • Accompany the line with a comment like // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading local file is OK. in order to disable the sniff. The actual plugin review process may or may not ignore comments like these. But it would at least put up a strong argument that we are aware of the situation and that we are facing a false-positive here.

cc @mmaymo

Reproduction instructions

  • Download & install a package that uses modularity, for example Mollie which made us aware of the issue
  • Download & install Plugin Check
  • Execute tests ( wp plugin check <PLUGIN_FILE>.php )

Expected behavior

In a perfect world, we would see no complaints originating from modularity

Environment info

No response

Relevant log output

FILE: lib/packages/Inpsyde/Modularity/Properties/LibraryProperties.php 43	29	ERROR	WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents	file_get_contents() is discouraged. Use wp_remote_get() for remote URLs instead.

Additional context

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Biont avatar Aug 09 '24 13:08 Biont