publishpress / PublishPress-Authors

PublishPress Authors is the best plugin for adding many authors to one WordPress post. You can create multiple authors, co-authors and guest authors.
14 stars 9 forks source link

Fix errors found by static code analysis to remove error flags raised by the IDE #1937

Open andergmartins opened 2 days ago

andergmartins commented 2 days ago

Expected Behavior

When opening the plugin's code in my IDE (Cursor), I expect not to see error flags about classes that are not found.

image

image

Current Behavior

The class MA_Wpengine_Integration is flagged with an error in the method flushWPECache because the class \WpeCommon does not exist on the project. The flag is correct since that class is only defined when that 3rd party plugin is installed, but we have options to keep its functionality and still avoid those flags.

Possible Solution

Refactor the method flushWPECache using method_exists instead of function_exists and using call_user_func instead of mentioning the class name directly. Something like the following snippet

if (method_exists('WpeCommon', 'purge_memcached')) {
    call_user_func(['WpeCommon', 'purge_memcached']);
}

Using that snippet, we mention the class name as a string, not triggering the errors, considering it will only be called if the class is also defined.

andergmartins commented 2 days ago

I've found a similar issue on src/core/Classes/Utils.php:

Undefined function et_get_theme_version

Use call_user_func on that function.

image

Undefined constant ELEMENTOR_PRO_VERSION

Use constant('ELEMENTOR_PRO_VERSION') instead of the constant directly.

image

Undefined constant WPSEO_VERSION

Also use constant(.....

image