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

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

Open
andergmartins opened this issue Dec 2, 2024 · 1 comment
Assignees

Comments

@andergmartins
Copy link
Contributor

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
Copy link
Contributor Author

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

@andergmartins andergmartins changed the title Refactor method MA_Wpengine_Integration::flushWPECache to fix error flags in the IDE Fix errors found by static code analysis to remove error flags raised by the IDE Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants