Skip to content

Commit 9d67cdd

Browse files
committed
[static-analysis] Fix php errors from static analysis
1 parent cdc9c70 commit 9d67cdd

File tree

11 files changed

+53
-43
lines changed

11 files changed

+53
-43
lines changed

includes/class-freemius.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $b
10031003

10041004
if ( isset( $install->plan ) && is_object( $install->plan ) ) {
10051005
if ( isset( $install->plan->id ) && ! empty( $install->plan->id ) ) {
1006-
$install->plan_id = self::_decrypt( $install->plan->id );
1006+
$install->plan_id = self::_decrypt( $install->plan->id ); // @phpstan-ignore-line
10071007
}
10081008

10091009
unset( $install->plan );
@@ -1882,7 +1882,7 @@ private function clear_module_main_file_cache( $store_prev_path = true ) {
18821882
$plugin_main_file = clone $this->_storage->plugin_main_file;
18831883

18841884
// Store cached path (2nd layer cache).
1885-
$plugin_main_file->prev_path = $plugin_main_file->path;
1885+
$plugin_main_file->prev_path = $plugin_main_file->path; // @phpstan-ignore-line
18861886

18871887
// Clear cached path.
18881888
unset( $plugin_main_file->path );
@@ -6266,9 +6266,6 @@ function is_org_repo_compliant() {
62666266
private function get_cron_data( $name ) {
62676267
$this->_logger->entrance( $name );
62686268

6269-
/**
6270-
* @var object $cron_data
6271-
*/
62726269
return $this->_storage->get( "{$name}_cron", null );
62736270
}
62746271

@@ -8925,7 +8922,6 @@ function skip_connection( $network_or_blog_ids = false ) {
89258922
* @since 2.0.0
89268923
*
89278924
* @param int|null $blog_id
8928-
* @param bool $send_skip
89298925
*/
89308926
private function skip_site_connection( $blog_id = null ) {
89318927
$this->_logger->entrance();
@@ -8959,7 +8955,7 @@ private function update_plugin_version_event() {
89598955
* @author Vova Feldman (@svovaf)
89608956
* @since 2.0.0
89618957
*
8962-
* @param array [string]array $plugins
8958+
* @param string[] $plugins
89638959
*
89648960
* @return string
89658961
*/
@@ -9374,7 +9370,7 @@ private function get_install_data_for_api(
93749370
* @author Vova Feldman (@svovaf)
93759371
* @since 2.0.0
93769372
*
9377-
* @param string[] string $override
9373+
* @param string[] $override
93789374
* @param bool $only_diff
93799375
* @param bool $is_keepalive
93809376
* @param bool $include_plugins Since 1.1.8 by default include plugin changes.
@@ -9561,7 +9557,7 @@ private function get_installs_data_for_api(
95619557
*
95629558
* @param array $site
95639559
* @param FS_Site $install
9564-
* @param string[] string $override
9560+
* @param string[] $override
95659561
*
95669562
* @return array
95679563
*/
@@ -9683,7 +9679,7 @@ function send_clone_resolution_update( $resolution_type, $clone_context_install
96839679
* @author Vova Feldman (@svovaf)
96849680
* @since 1.0.9
96859681
*
9686-
* @param string[] string $override
9682+
* @param string[] $override
96879683
* @param bool $flush
96889684
* @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
96899685
*
@@ -9756,7 +9752,7 @@ private function send_install_update( $override = array(), $flush = false, $is_t
97569752
* @author Vova Feldman (@svovaf)
97579753
* @since 2.0.0
97589754
*
9759-
* @param string[] string $override
9755+
* @param string[] $override
97609756
* @param bool $flush
97619757
* @param bool $is_two_way_sync @since 2.5.0 If true and there's a successful API request, the install sync cron will be cleared.
97629758
*
@@ -9843,7 +9839,7 @@ private function maybe_sync_install_user() {
98439839
* @author Vova Feldman (@svovaf)
98449840
* @since 1.0.9
98459841
*
9846-
* @param string[] string $override
9842+
* @param string[] $override
98479843
* @param bool $flush
98489844
*/
98499845
function sync_install( $override = array(), $flush = false ) {
@@ -9872,7 +9868,7 @@ function sync_install( $override = array(), $flush = false ) {
98729868
* @author Vova Feldman (@svovaf)
98739869
* @since 1.0.9
98749870
*
9875-
* @param string[] string $override
9871+
* @param string[] $override
98769872
* @param bool $flush
98779873
*/
98789874
private function sync_installs( $override = array(), $flush = false ) {
@@ -19899,7 +19895,7 @@ function has_filter( $tag, $function_to_check = false ) {
1989919895
* @author Vova Feldman (@svovaf)
1990019896
* @since 1.1.6
1990119897
*
19902-
* @param string[] string $key_value
19898+
* @param string[] $key_value
1990319899
*
1990419900
* @uses fs_override_i18n()
1990519901
*/
@@ -22839,8 +22835,8 @@ private function complete_change_owner() {
2283922835
* @author Leo Fajardo (@leorw)
2284022836
* @since 2.3.2
2284122837
*
22842-
* @param number $user_id
22843-
* @param array[string]number $install_ids_by_slug_map
22838+
* @param number $user_id
22839+
* @param string[]|int[] $install_ids_by_slug_map
2284422840
*
2284522841
*/
2284622842
private function complete_ownership_change_by_license( $user_id, $install_ids_by_slug_map ) {
@@ -26047,9 +26043,6 @@ function _maybe_show_gdpr_admin_notice() {
2604726043
return;
2604826044
}
2604926045

26050-
/**
26051-
* @var $current_wp_user WP_User
26052-
*/
2605326046
$current_wp_user = self::_get_current_wp_user();
2605426047

2605526048
/**

includes/class-fs-plugin-updater.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,9 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10701070

10711071
// Fetch as much as possible info from local files.
10721072
$plugin_local_data = $this->_fs->get_plugin_data();
1073-
$data->name = $plugin_local_data['Name'];
1074-
$data->author = $plugin_local_data['Author'];
1075-
$data->sections = array(
1076-
'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
1077-
);
1073+
$data->name = $plugin_local_data['Name']; // @phpstan-ignore-line
1074+
$data->author = $plugin_local_data['Author']; // @phpstan-ignore-line
1075+
$data->sections = array( 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.' ); // @phpstan-ignore-line
10781076

10791077
// @todo Store extra plugin info on Freemius or parse readme.txt markup.
10801078
/*$info = $this->_fs->get_api_site_scope()->call('/information.json');
@@ -1098,18 +1096,18 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10981096
$data->name = $addon->title . ' ' . $this->_fs->get_text_inline( 'Add-On', 'addon' );
10991097
$data->slug = $addon->slug;
11001098
$data->url = WP_FS__ADDRESS;
1101-
$data->package = $new_version->url;
1099+
$data->package = $new_version->url; // @phpstan-ignore-line
11021100
}
11031101

11041102
if ( ! $plugin_in_repo ) {
1105-
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
1106-
$data->requires = $new_version->requires_platform_version;
1107-
$data->requires_php = $new_version->requires_programming_language_version;
1108-
$data->tested = $new_version->tested_up_to_version;
1103+
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created; // @phpstan-ignore-line
1104+
$data->requires = $new_version->requires_platform_version; // @phpstan-ignore-line
1105+
$data->requires_php = $new_version->requires_programming_language_version; // @phpstan-ignore-line
1106+
$data->tested = $new_version->tested_up_to_version; // @phpstan-ignore-line
11091107
}
11101108

11111109
$data->version = $new_version->version;
1112-
$data->download_link = $new_version->url;
1110+
$data->download_link = $new_version->url; // @phpstan-ignore-line
11131111

11141112
if ( isset( $new_version->readme ) && is_object( $new_version->readme ) ) {
11151113
$new_version_readme_data = $new_version->readme;

includes/entities/class-fs-entity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static function equals( $entity1, $entity2 ) {
8888
* @author Vova Feldman (@svovaf)
8989
* @since 1.0.9
9090
*
91-
* @param string|array[string]mixed $key
92-
* @param string|bool $val
91+
* @param array|string[] $key
92+
* @param string|bool $val
9393
*
9494
* @return bool
9595
*/

includes/fs-core-functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,8 +1389,8 @@ function fs_esc_html_echo_inline( $text, $key = '', $slug = 'freemius' ) {
13891389
* @author Vova Feldman (@svovaf)
13901390
* @since 1.1.6
13911391
*
1392-
* @param array[string]string $key_value
1393-
* @param string $slug
1392+
* @param array|string[] $key_value
1393+
* @param string $slug
13941394
*
13951395
* @global $fs_text_overrides
13961396
*/

includes/fs-essential-functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false
264264
$in_activation = ( ! is_plugin_active( $plugin_file ) );
265265
} else {
266266
$theme = wp_get_theme();
267-
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
267+
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet ); // @phpstan-ignore-line
268268
}
269269

270270
$fs_active_plugins->newest = (object) array(

includes/fs-plugin-info-dialog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private function get_checkout_cta( $api, $plan = null ) {
527527
$plan->plugin_id,
528528
$plan->pricing[0]->id,
529529
$this->get_billing_cycle( $plan ),
530-
$plan->has_trial(),
530+
$plan->has_trial(), // @phpstan-ignore-line
531531
( $has_valid_blog_id ? false : null )
532532
);
533533

@@ -536,7 +536,7 @@ private function get_checkout_cta( $api, $plan = null ) {
536536
}
537537

538538
return '<a class="button button-primary fs-checkout-button right" href="' . $addon_checkout_url . '" target="_parent">' .
539-
esc_html( ! $plan->has_trial() ?
539+
esc_html( ! $plan->has_trial() ? // @phpstan-ignore-line
540540
(
541541
$api->has_purchased_license ?
542542
fs_text_inline( 'Purchase More', 'purchase-more', $api->slug ) :

includes/managers/class-fs-cache-manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ function get( $key, $default = null ) {
166166
isset( $cache_entry->timestamp ) &&
167167
is_numeric( $cache_entry->timestamp )
168168
) {
169-
return $cache_entry->result;
169+
return $cache_entry->result; // @phpstan-ignore-line
170+
170171
}
171172

172173
return is_object( $default ) ? clone $default : $default;

includes/managers/class-fs-permission-manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ function render_permissions_group( array $permissions_group ) {
638638
fs_require_template( 'connect/permissions-group.php', $permissions_group );
639639
}
640640

641-
function require_permissions_js() {
641+
function require_permissions_js( $params ) {
642642
fs_require_once_template( 'js/permissions.php', $params );
643643
}
644644

phpstan.neon

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 1
2+
level: 2
33
paths:
44
- config.php
55
- start.php
@@ -9,6 +9,20 @@ parameters:
99
bootstrapFiles:
1010
- .phpstan/exceptions.php
1111
ignoreErrors:
12+
-
13+
message: '#PHPDoc tag @var has invalid value#'
14+
path: includes/managers/class-fs-plugin-manager.php
15+
-
16+
message: '#PHPDoc tag @use has invalid value#'
17+
path: includes/class-freemius.php
18+
-
19+
message: '#PHPDoc tag @var above a method has no effect.#'
20+
path: includes/class-freemius.php
21+
-
22+
message: '#Access to an undefined property#'
23+
paths:
24+
- includes/class-freemius.php
25+
- includes/fs-plugin-info-dialog.php
1226
-
1327
message: '#will always evaluate to true#'
1428
path: includes/class-fs-plugin-updater.php

templates/add-ons.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@
141141
continue;
142142
}
143143

144-
145144
$has_paid_plan = true;
146-
$has_trial = $has_trial || ( is_numeric( $plan->trial_period ) && ( $plan->trial_period > 0 ) );
145+
146+
if ( isset( $plan->trial_period ) ) {
147+
$has_trial = ( is_numeric( $plan->trial_period ) && ( $plan->trial_period > 0 ) );
148+
}
147149

148150
$min_price = 999999;
149151
foreach ( $plan->pricing as $pricing ) {

0 commit comments

Comments
 (0)