Skip to content

Commit 6ee7406

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

File tree

13 files changed

+88
-73
lines changed

13 files changed

+88
-73
lines changed

includes/class-freemius.php

Lines changed: 24 additions & 20 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
*/
@@ -9888,13 +9887,15 @@ private function sync_installs( $override = array(), $flush = false ) {
98889887

98899888
$address_to_blog_map = $this->get_address_to_blog_map();
98909889

9891-
foreach ( $result->installs as $install ) {
9892-
$this->_site = new FS_Site( $install );
9890+
if ( ! empty( $result->installs ) ) {
9891+
foreach ( $result->installs as $install ) {
9892+
$this->_site = new FS_Site( $install );
98939893

9894-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
9895-
$blog_id = $address_to_blog_map[ $address ];
9894+
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
9895+
$blog_id = $address_to_blog_map[ $address ];
98969896

9897-
$this->_store_site( true, $blog_id );
9897+
$this->_store_site( true, $blog_id );
9898+
}
98989899
}
98999900
}
99009901

@@ -14101,7 +14102,7 @@ private function activate_license(
1410114102
$result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
1410214103
}
1410314104

14104-
if ( true === $result && count( $site_ids ) > 0 ) {
14105+
if ( true === $result && ! empty( $site_ids ) > 0 ) {
1410514106
$result = $fs->activate_license_on_many_sites( $user, $license_key, $site_ids );
1410614107
}
1410714108
} else {
@@ -20057,7 +20058,7 @@ private function _store_licenses( $store = true, $module_id = false, $licenses =
2005720058
}
2005820059
}
2005920060

20060-
if ( count( $new_user_licenses_map ) > 0 ) {
20061+
if ( ! empty( $new_user_licenses_map ) > 0 ) {
2006120062
// Add new licenses.
2006220063
$all_licenses[ $module_id ] = array_merge( array_values( $new_user_licenses_map ), $all_licenses[ $module_id ] );
2006320064
}
@@ -21303,14 +21304,17 @@ private function _sync_plugin_license(
2130321304

2130421305
// Find the current context install.
2130521306
$site = null;
21306-
foreach ( $result->installs as $install ) {
21307-
if ( $install->id == $this->_site->id ) {
21308-
$site = new FS_Site( $install );
21309-
} else {
21310-
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
21311-
$blog_id = $address_to_blog_map[ $address ];
2131221307

21313-
$this->_store_site( true, $blog_id, new FS_Site( $install ) );
21308+
if ( ! empty( $result->installs ) ) {
21309+
foreach ( $result->installs as $install ) {
21310+
if ( $install->id == $this->_site->id ) {
21311+
$site = new FS_Site( $install );
21312+
} else {
21313+
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
21314+
$blog_id = $address_to_blog_map[ $address ];
21315+
21316+
$this->_store_site( true, $blog_id, new FS_Site( $install ) );
21317+
}
2131421318
}
2131521319
}
2131621320
}

includes/class-fs-plugin-updater.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10491049
false
10501050
);
10511051

1052-
if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) {
1052+
if ( isset( $addon_plugin_data['Version'] ) ) {
10531053
$addon_version = $addon_plugin_data['Version'];
10541054
}
10551055
}
@@ -1070,9 +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']; // @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
1073+
$data->name = $plugin_local_data['Name'];
1074+
$data->author = $plugin_local_data['Author'];
1075+
$data->sections = array( 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.' );
10761076

10771077
// @todo Store extra plugin info on Freemius or parse readme.txt markup.
10781078
/*$info = $this->_fs->get_api_site_scope()->call('/information.json');
@@ -1096,18 +1096,18 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
10961096
$data->name = $addon->title . ' ' . $this->_fs->get_text_inline( 'Add-On', 'addon' );
10971097
$data->slug = $addon->slug;
10981098
$data->url = WP_FS__ADDRESS;
1099-
$data->package = $new_version->url; // @phpstan-ignore-line
1099+
$data->package = $new_version->url;
11001100
}
11011101

11021102
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
1103+
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
1104+
$data->requires = $new_version->requires_platform_version;
1105+
$data->requires_php = $new_version->requires_programming_language_version;
1106+
$data->tested = $new_version->tested_up_to_version;
11071107
}
11081108

11091109
$data->version = $new_version->version;
1110-
$data->download_link = $new_version->url; // @phpstan-ignore-line
1110+
$data->download_link = $new_version->url;
11111111

11121112
if ( isset( $new_version->readme ) && is_object( $new_version->readme ) ) {
11131113
$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 ( isset( $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-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,33 @@ parameters:
1818
-
1919
message: '#PHPDoc tag @var above a method has no effect.#'
2020
path: includes/class-freemius.php
21+
-
22+
message: '#Action callback returns bool but should not return anything.#'
23+
path: includes/class-freemius.php
24+
-
25+
message: '#Variable \$site_ids in empty\(\) always exists and is always falsy.#'
26+
path: includes/class-freemius.php
27+
-
28+
message: '#Variable \$new_user_licenses_map in empty\(\) always exists and is not falsy.#'
29+
path: includes/class-freemius.php
2130
-
2231
message: '#Access to an undefined property#'
2332
paths:
33+
- start.php
34+
- templates/debug.php
35+
- templates/add-ons.php
36+
- templates/plugin-info/features.php
2437
- includes/class-freemius.php
2538
- includes/fs-plugin-info-dialog.php
39+
- includes/fs-essential-functions.php
40+
- includes/class-fs-plugin-updater.php
41+
- includes/managers/class-fs-cache-manager.php
2642
-
2743
message: '#will always evaluate to true#'
2844
path: includes/class-fs-plugin-updater.php
45+
-
46+
message: '#Call to an undefined method object::has_trial\(\)#'
47+
path: includes/fs-plugin-info-dialog.php
2948
-
3049
message: '#Variable \$VARS might not be defined#'
3150
paths:

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
}

templates/account/partials/addon.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
$show_upgrade = false;
6868
$is_whitelabeled = $VARS['is_whitelabeled'];
6969

70+
$version = '';
71+
$plan_name = '';
72+
$plan_title = '';
73+
7074
if ( is_object( $fs_addon ) ) {
7175
$is_paying = $fs_addon->is_paying();
7276
$user = $fs_addon->get_user();
@@ -158,11 +162,11 @@
158162
<!--/ ID -->
159163

160164
<!-- Version -->
161-
<td><?php echo $version; // @phpstan-ignore-line ?></td>
165+
<td><?php echo $version; ?></td>
162166
<!--/ Version -->
163167

164168
<!-- Plan Title -->
165-
<td><?php echo strtoupper( is_string( $plan_name ) ? $plan_title : $free_text ); // @phpstan-ignore-line ?></td>
169+
<td><?php echo strtoupper( is_string( $plan_name ) ? $plan_title : $free_text ); ?></td>
166170
<!--/ Plan Title -->
167171

168172
<!-- Expiration -->

0 commit comments

Comments
 (0)