Skip to content

Commit ae44f1c

Browse files
committed
[static-analysis] Escape rules not following the logic of the code.
1 parent cce450d commit ae44f1c

File tree

14 files changed

+79
-72
lines changed

14 files changed

+79
-72
lines changed

includes/class-freemius.php

Lines changed: 8 additions & 9 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 ); // @phpstan-ignore-line
1006+
$install->plan_id = self::_decrypt( $install->plan->id );
10071007
}
10081008

10091009
unset( $install->plan );
@@ -1564,8 +1564,8 @@ private function register_constructor_hooks() {
15641564
);
15651565
$this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );
15661566

1567-
add_action( 'admin_init', array( &$this, '_add_trial_notice' ) ); // @phpstan-ignore-line
1568-
add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) ); // @phpstan-ignore-line
1567+
add_action( 'admin_init', array( &$this, '_add_trial_notice' ) );
1568+
add_action( 'admin_init', array( &$this, '_add_affiliate_program_notice' ) );
15691569
add_action( 'admin_enqueue_scripts', array( &$this, '_enqueue_common_css' ) );
15701570

15711571
/**
@@ -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; // @phpstan-ignore-line
1885+
$plugin_main_file->prev_path = $plugin_main_file->path;
18861886

18871887
// Clear cached path.
18881888
unset( $plugin_main_file->path );
@@ -8016,7 +8016,6 @@ private function maybe_network_activate_addon_license( $license = null ) {
80168016
}
80178017
}
80188018

8019-
// @phpstan-ignore-next-line
80208019
if ( ! empty( $site_ids ) ) {
80218020
$this->activate_license_on_many_sites( $user, $license->secret_key, $site_ids );
80228021
}
@@ -8955,7 +8954,7 @@ private function update_plugin_version_event() {
89558954
* @author Vova Feldman (@svovaf)
89568955
* @since 2.0.0
89578956
*
8958-
* @param string[] $plugins
8957+
* @param array<string, array> $plugins
89598958
*
89608959
* @return string
89618960
*/
@@ -14101,7 +14100,7 @@ private function activate_license(
1410114100
$result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
1410214101
}
1410314102

14104-
if ( true === $result && count( $site_ids ) > 0 ) {
14103+
if ( true === $result && ! empty( $site_ids ) > 0 ) {
1410514104
$result = $fs->activate_license_on_many_sites( $user, $license_key, $site_ids );
1410614105
}
1410714106
} else {
@@ -19923,7 +19922,7 @@ private function _store_site( $store = true, $network_level_or_blog_id = null, F
1992319922
$site = $this->_site;
1992419923
}
1992519924

19926-
if ( !is_object($site) || empty( $site->id ) ) {
19925+
if ( ! is_object( $site ) || empty( $site->id ) ) {
1992719926
$this->_logger->error( "Empty install ID, can't store site." );
1992819927

1992919928
return;
@@ -20057,7 +20056,7 @@ private function _store_licenses( $store = true, $module_id = false, $licenses =
2005720056
}
2005820057
}
2005920058

20060-
if ( count( $new_user_licenses_map ) > 0 ) {
20059+
if ( ! empty( $new_user_licenses_map ) ) {
2006120060
// Add new licenses.
2006220061
$all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
2006320062
}

includes/class-fs-plugin-updater.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ function pre_set_site_transient_update_plugins_filter( $transient_data ) {
499499
return $transient_data;
500500
}
501501

502-
// @phpstan-ignore-next-line
503502
if ( empty( $transient_data ) ||
504503
defined( 'WP_FS__UNINSTALL_MODE' )
505504
) {
@@ -1049,7 +1048,7 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10491048
false
10501049
);
10511050

1052-
if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) {
1051+
if ( ! empty( $addon_plugin_data['Version'] ) ) {
10531052
$addon_version = $addon_plugin_data['Version'];
10541053
}
10551054
}
@@ -1070,9 +1069,11 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10701069

10711070
// Fetch as much as possible info from local files.
10721071
$plugin_local_data = $this->_fs->get_plugin_data();
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
1072+
$data->name = $plugin_local_data['Name'];
1073+
$data->author = $plugin_local_data['Author'];
1074+
$data->sections = array(
1075+
'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.'
1076+
);
10761077

10771078
// @todo Store extra plugin info on Freemius or parse readme.txt markup.
10781079
/*$info = $this->_fs->get_api_site_scope()->call('/information.json');
@@ -1096,18 +1097,18 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10961097
$data->name = $addon->title . ' ' . $this->_fs->get_text_inline( 'Add-On', 'addon' );
10971098
$data->slug = $addon->slug;
10981099
$data->url = WP_FS__ADDRESS;
1099-
$data->package = $new_version->url; // @phpstan-ignore-line
1100+
$data->package = $new_version->url;
11001101
}
11011102

11021103
if ( ! $plugin_in_repo ) {
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
1104+
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
1105+
$data->requires = $new_version->requires_platform_version;
1106+
$data->requires_php = $new_version->requires_programming_language_version;
1107+
$data->tested = $new_version->tested_up_to_version;
11071108
}
11081109

11091110
$data->version = $new_version->version;
1110-
$data->download_link = $new_version->url; // @phpstan-ignore-line
1111+
$data->download_link = $new_version->url;
11111112

11121113
if ( isset( $new_version->readme ) && is_object( $new_version->readme ) ) {
11131114
$new_version_readme_data = $new_version->readme;

includes/entities/class-fs-entity.php

Lines changed: 3 additions & 3 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 array|string[] $key
92-
* @param string|bool $val
91+
* @param string|array<string, mixed> $key
92+
* @param string|bool $val
9393
*
9494
* @return bool
9595
*/
@@ -156,4 +156,4 @@ static function is_valid_id($id){
156156
public static function get_class_name() {
157157
return get_called_class();
158158
}
159-
}
159+
}

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[] $key_value
1393-
* @param string $slug
1392+
* @param array<string, string> $key_value
1393+
* @param string $slug
13941394
*
13951395
* @global $fs_text_overrides
13961396
*/

includes/fs-essential-functions.php

Lines changed: 2 additions & 2 deletions
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 ); // @phpstan-ignore-line
267+
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
268268
}
269269

270270
$fs_active_plugins->newest = (object) array(
@@ -415,4 +415,4 @@ function fs_fallback_to_newest_active_sdk() {
415415
fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
416416
}
417417
}
418-
}
418+
}

includes/fs-plugin-info-dialog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function _get_addon_info_filter( $data, $action = '', $args = null ) {
229229
false
230230
);
231231

232-
if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) {
232+
if ( ! empty( $addon_plugin_data['Version'] ) ) {
233233
$current_addon_version = $addon_plugin_data['Version'];
234234
}
235235
}
@@ -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(), // @phpstan-ignore-line
530+
$plan->has_trial(),
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() ? // @phpstan-ignore-line
539+
esc_html( ! $plan->has_trial() ?
540540
(
541541
$api->has_purchased_license ?
542542
fs_text_inline( 'Purchase More', 'purchase-more', $api->slug ) :

includes/managers/class-fs-admin-menu-manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,4 +1004,4 @@ function add_subpage_and_update(
10041004
$function
10051005
);
10061006
}
1007-
}
1007+
}

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

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

173172
return is_object( $default ) ? clone $default : $default;
@@ -324,4 +323,4 @@ function migrate_to_network() {
324323
}
325324

326325
#endregion
327-
}
326+
}

phpstan.neon

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,36 @@ parameters:
1010
- .phpstan/exceptions.php
1111
ignoreErrors:
1212
-
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.#'
13+
messages:
14+
- '#PHPDoc tag @use has invalid value#'
15+
- '#PHPDoc tag @var above a method has no effect.#'
16+
- '#Action callback returns bool but should not return anything.#'
17+
- '#Variable \$site_ids in empty\(\) always exists and is always falsy.#'
18+
- '#Variable \$new_user_licenses_map in empty\(\) always exists and is not falsy.#'
19+
- '#Cannot access property \$installs#'
2020
path: includes/class-freemius.php
2121
-
2222
message: '#Access to an undefined property#'
2323
paths:
24+
- start.php
25+
- templates/debug.php
26+
- templates/add-ons.php
27+
- templates/plugin-info/features.php
2428
- includes/class-freemius.php
2529
- includes/fs-plugin-info-dialog.php
30+
- includes/fs-essential-functions.php
31+
- includes/class-fs-plugin-updater.php
32+
- includes/managers/class-fs-cache-manager.php
33+
-
34+
message: '#Call to an undefined method object::has_trial\(\)#'
35+
path: includes/fs-plugin-info-dialog.php
36+
-
37+
message: '#PHPDoc tag @var has invalid value#'
38+
path: includes/managers/class-fs-plugin-manager.php
2639
-
27-
message: '#will always evaluate to true#'
40+
messages:
41+
- '#Variable \$transient_data in empty\(\) always exists and is not falsy.#'
42+
- '#will always evaluate to true#'
2843
path: includes/class-fs-plugin-updater.php
2944
-
3045
message: '#Variable \$VARS might not be defined#'

templates/account.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@
9696
) );
9797
}
9898

99+
$payments = [];
99100
$show_billing = ( ! $is_whitelabeled && ! $fs->apply_filters( 'hide_billing_and_payments_info', false ) );
100101
if ( $show_billing ) {
101-
$payments = $fs->_fetch_payments();
102-
103-
$show_billing = ( is_array( $payments ) && 0 < count( $payments ) );
102+
$payments = $fs->_fetch_payments();
103+
$show_billing = ( 0 < count( $payments ) );
104104
}
105105

106-
107106
$has_tabs = $fs->_add_tabs_before_content();
108107

109108
// Aliases.
@@ -137,8 +136,7 @@
137136

138137
$show_plan_row = true;
139138
$show_license_row = is_object( $license );
140-
141-
$site_view_params = array();
139+
$site_view_params = array();
142140

143141
if ( fs_is_network_admin() ) {
144142
$sites = Freemius::get_sites();
@@ -157,7 +155,7 @@
157155

158156
$site_view_params[] = $view_params;
159157

160-
if ( is_object( $install ) ) {
158+
if ( ! is_object( $install ) ) {
161159
continue;
162160
}
163161

@@ -871,7 +869,7 @@ class="fs-tag fs-<?php echo $fs->can_use_premium_code() ? 'success' : 'warn' ?>"
871869

872870
<?php
873871
if ( $show_billing ) {
874-
$view_params = array( 'id' => $VARS['id'], 'payments' => $payments ); // @phpstan-ignore-line
872+
$view_params = array( 'id' => $VARS['id'], 'payments' => $payments );
875873
fs_require_once_template( 'account/billing.php', $view_params );
876874
fs_require_once_template( 'account/payments.php', $view_params );
877875
}

0 commit comments

Comments
 (0)