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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking if plugin status is not install #1127

Merged
merged 2 commits into from Apr 12, 2024

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Apr 12, 2024

This is a sub-PR of #1126 which is also about fixing issues that PHPStan's static analysis uncovered. In PHPStan level 4:

basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.

The following issues were reported in includes/admin/plugins.php:

  167    Result of || is always true.                                                                                                                       
         馃挕 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.         
  167    Strict comparison using !== between 'install' and array{status: string, url: string, version: string, file: string} will always evaluate to true.  
         馃挕 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.         
  189    Result of || is always true.                                                                                                                       
         馃挕 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.         
  189    Strict comparison using !== between 'install' and array{status: string, url: string, version: string, file: string} will always evaluate to true. 

The $status variable is populated with the return value of install_plugin_install_status() which is always an array with these keys:

image

Therefore, the current checks for 'install' !== $status will always evaluate to false because $status is always an array and never a string.

This was introduced in #1091. We need to make sure that fixing this static analysis bug doesn't cause a regression in the expected behavior.

Again, to prevent this from happening in the future, we need to increase the PHPStan level from 0 (#775).

@westonruter westonruter added [Type] Bug An existing feature is broken Performance Lab Plugin Issue relates to work in the Performance Lab Plugin only skip changelog PRs that should not be mentioned in changelogs labels Apr 12, 2024
@westonruter westonruter added this to the performance-lab 3.0.0 milestone Apr 12, 2024
Copy link

github-actions bot commented Apr 12, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Wow, this is a pretty severe bug (not security-wise, but UX-wise). Glad you caught this! 馃帀

@westonruter
Copy link
Member Author

PHPStan caught it. I'm just the messenger 馃榾

Base automatically changed from fix/plugin-activation-error-messages to release/3.0.0 April 12, 2024 04:13
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃殌

@mukeshpanchal27 mukeshpanchal27 merged commit 5973a24 into release/3.0.0 Apr 12, 2024
15 checks passed
@mukeshpanchal27 mukeshpanchal27 deleted the fix/plugin-install-status branch April 12, 2024 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Lab Plugin Issue relates to work in the Performance Lab Plugin only skip changelog PRs that should not be mentioned in changelogs [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants