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
[static-analysis] Fix static analysis level 1 errors. #679
base: develop
Are you sure you want to change the base?
Conversation
1b17dbe
to
2419e91
Compare
templates/account.php
Outdated
@@ -482,7 +483,7 @@ class="dashicons dashicons-image-rotate"></i> <?php fs_esc_html_echo_x_inline( ' | |||
$profile[] = array( | |||
'id' => 'bundle_plan', | |||
'title' => $bundle_plan_text, | |||
'value' => $bundle_plan_title | |||
'value' => $bundle_title |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa Please check the comment above.
templates/account.php
Outdated
@@ -468,10 +468,11 @@ class="dashicons dashicons-image-rotate"></i> <?php fs_esc_html_echo_x_inline( ' | |||
); | |||
} | |||
} else { | |||
$bundle_title = ( $has_bundle_license ? ucfirst( $fs->get_module_type() ) : '' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa Please check the comments below.
…. 2 parameters given but 1 required.
…iables are misnamed in code that follows.
83a307d
to
9d67cdd
Compare
bfd1c8d
to
48aaba0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa please see my comments, thanks.
@@ -8958,7 +8955,7 @@ private function update_plugin_version_event() { | |||
* @author Vova Feldman (@svovaf) | |||
* @since 2.0.0 | |||
* | |||
* @param array [string]array $plugins | |||
* @param string[] $plugins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa The correct php-doc type would be array<string, array>
. This is not an array of string
:)
@@ -14104,7 +14101,7 @@ private function activate_license( | |||
$result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map ); | |||
} | |||
|
|||
if ( true === $result && ! empty( $site_ids ) ) { | |||
if ( true === $result && count( $site_ids ) > 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa why this change? What rule was it breaking?
@@ -14323,6 +14320,7 @@ private function get_parent_and_addons_installs_info() { | |||
) | |||
); | |||
|
|||
$installed_addons_ids_map = array_flip( $installed_addons_ids ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a bug fix?
@@ -20061,7 +20057,7 @@ private function _store_licenses( $store = true, $module_id = false, $licenses = | |||
} | |||
} | |||
|
|||
if ( ! empty( $new_user_licenses_map ) ) { | |||
if ( count( $new_user_licenses_map ) > 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something PHPStan is forcing us to do?
@@ -1048,7 +1049,7 @@ function plugins_api_filter( $data, $action = '', $args = null ) { | |||
false | |||
); | |||
|
|||
if ( ! empty( $addon_plugin_data ) ) { | |||
if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, that return type of get_plugin_data
is array
, yet we have to check with is_array
here again. Maybe if you feed PHPStan with some WP stub, it will not give these false positives?
@@ -166,7 +166,8 @@ function get( $key, $default = null ) { | |||
isset( $cache_entry->timestamp ) && | |||
is_numeric( $cache_entry->timestamp ) | |||
) { | |||
return $cache_entry->result; | |||
return $cache_entry->result; // @phpstan-ignore-line | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this empty line please.
@@ -157,7 +157,7 @@ | |||
|
|||
$site_view_params[] = $view_params; | |||
|
|||
if ( empty( $install ) ) { | |||
if ( is_object( $install ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug 😓 . if ( ! is_object( $install ) )
$has_trial = $has_trial || ( is_numeric( $plan->trial_period ) && ( $plan->trial_period > 0 ) ); | ||
|
||
if ( isset( $plan->trial_period ) ) { | ||
$has_trial = ( is_numeric( $plan->trial_period ) && ( $plan->trial_period > 0 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bahiirwa why not
$has_trial = isset( $plan->trial_period ) && is_numeric(...) && $plan->trial_period > 0;
|
||
$active_modules_by_id[ $data->id ] = true; | ||
} | ||
?> | ||
<tr<?php if ( $is_active ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change needed for PHPStan?
@@ -27,7 +27,9 @@ | |||
$features_plan_map[ $feature->id ] = array( 'feature' => $feature, 'plans' => array() ); | |||
} | |||
|
|||
$features_plan_map[ $feature->id ]['plans'][ $plan->id ] = $feature; | |||
if ( ! empty( $plan->id ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed changes
count()
You can advise on that. The goal was to maintain the checks in place and not modify functionality.