Skip to content

Commit

Permalink
[static-analysis] Escape rules not following the logic of the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bahiirwa committed Jun 16, 2024
1 parent cce450d commit fe76177
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 73 deletions.
44 changes: 24 additions & 20 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $b

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

unset( $install->plan );
Expand Down Expand Up @@ -1564,8 +1564,8 @@ private function register_constructor_hooks() {
);
$this->add_filter( 'after_code_type_change', array( &$this, '_after_code_type_change' ) );

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

/**
Expand Down Expand Up @@ -1882,7 +1882,7 @@ private function clear_module_main_file_cache( $store_prev_path = true ) {
$plugin_main_file = clone $this->_storage->plugin_main_file;

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

// Clear cached path.
unset( $plugin_main_file->path );
Expand Down Expand Up @@ -8016,7 +8016,6 @@ private function maybe_network_activate_addon_license( $license = null ) {
}
}

// @phpstan-ignore-next-line
if ( ! empty( $site_ids ) ) {
$this->activate_license_on_many_sites( $user, $license->secret_key, $site_ids );
}
Expand Down Expand Up @@ -8955,7 +8954,7 @@ private function update_plugin_version_event() {
* @author Vova Feldman (@svovaf)
* @since 2.0.0
*
* @param string[] $plugins
* @param array<string, array> $plugins
*
* @return string
*/
Expand Down Expand Up @@ -9888,13 +9887,15 @@ private function sync_installs( $override = array(), $flush = false ) {

$address_to_blog_map = $this->get_address_to_blog_map();

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

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

$this->_store_site( true, $blog_id );
$this->_store_site( true, $blog_id );
}
}
}

Expand Down Expand Up @@ -14101,7 +14102,7 @@ private function activate_license(
$result = $fs->activate_license_on_many_installs( $user, $license_key, $blog_2_install_map );
}

if ( true === $result && count( $site_ids ) > 0 ) {
if ( true === $result && ! empty( $site_ids ) > 0 ) {
$result = $fs->activate_license_on_many_sites( $user, $license_key, $site_ids );
}
} else {
Expand Down Expand Up @@ -20057,7 +20058,7 @@ private function _store_licenses( $store = true, $module_id = false, $licenses =
}
}

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

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

$this->_store_site( true, $blog_id, new FS_Site( $install ) );
if ( ! empty( $result->installs ) ) {
foreach ( $result->installs as $install ) {
if ( $install->id == $this->_site->id ) {
$site = new FS_Site( $install );
} else {
$address = trailingslashit( fs_strip_url_protocol( $install->url ) );
$blog_id = $address_to_blog_map[ $address ];

$this->_store_site( true, $blog_id, new FS_Site( $install ) );
}
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions includes/class-fs-plugin-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
false
);

if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) {
if ( isset( $addon_plugin_data['Version'] ) ) {
$addon_version = $addon_plugin_data['Version'];
}
}
Expand All @@ -1070,9 +1070,9 @@ function plugins_api_filter( $data, $action = '', $args = null ) {

// Fetch as much as possible info from local files.
$plugin_local_data = $this->_fs->get_plugin_data();
$data->name = $plugin_local_data['Name']; // @phpstan-ignore-line
$data->author = $plugin_local_data['Author']; // @phpstan-ignore-line
$data->sections = array( 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.' ); // @phpstan-ignore-line
$data->name = $plugin_local_data['Name'];
$data->author = $plugin_local_data['Author'];
$data->sections = array( 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.' );

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

if ( ! $plugin_in_repo ) {
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created; // @phpstan-ignore-line
$data->requires = $new_version->requires_platform_version; // @phpstan-ignore-line
$data->requires_php = $new_version->requires_programming_language_version; // @phpstan-ignore-line
$data->tested = $new_version->tested_up_to_version; // @phpstan-ignore-line
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
$data->requires = $new_version->requires_platform_version;
$data->requires_php = $new_version->requires_programming_language_version;
$data->tested = $new_version->tested_up_to_version;
}

$data->version = $new_version->version;
$data->download_link = $new_version->url; // @phpstan-ignore-line
$data->download_link = $new_version->url;

if ( isset( $new_version->readme ) && is_object( $new_version->readme ) ) {
$new_version_readme_data = $new_version->readme;
Expand Down
6 changes: 3 additions & 3 deletions includes/entities/class-fs-entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ static function equals( $entity1, $entity2 ) {
* @author Vova Feldman (@svovaf)
* @since 1.0.9
*
* @param array|string[] $key
* @param string|bool $val
* @param string|array<string, mixed> $key
* @param string|bool $val
*
* @return bool
*/
Expand Down Expand Up @@ -156,4 +156,4 @@ static function is_valid_id($id){
public static function get_class_name() {
return get_called_class();
}
}
}
4 changes: 2 additions & 2 deletions includes/fs-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,8 @@ function fs_esc_html_echo_inline( $text, $key = '', $slug = 'freemius' ) {
* @author Vova Feldman (@svovaf)
* @since 1.1.6
*
* @param array|string[] $key_value
* @param string $slug
* @param array<string, string> $key_value
* @param string $slug
*
* @global $fs_text_overrides
*/
Expand Down
4 changes: 2 additions & 2 deletions includes/fs-essential-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function fs_update_sdk_newest_version( $sdk_relative_path, $plugin_file = false
$in_activation = ( ! is_plugin_active( $plugin_file ) );
} else {
$theme = wp_get_theme();
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet ); // @phpstan-ignore-line
$in_activation = ( $newest_sdk->plugin_path == $theme->stylesheet );
}

$fs_active_plugins->newest = (object) array(
Expand Down Expand Up @@ -415,4 +415,4 @@ function fs_fallback_to_newest_active_sdk() {
fs_update_sdk_newest_version( $newest_sdk_path, $newest_sdk_data->plugin_path );
}
}
}
}
6 changes: 3 additions & 3 deletions includes/fs-plugin-info-dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function _get_addon_info_filter( $data, $action = '', $args = null ) {
false
);

if ( is_array( $addon_plugin_data ) && isset( $addon_plugin_data['Version'] ) ) {
if ( isset( $addon_plugin_data['Version'] ) ) {
$current_addon_version = $addon_plugin_data['Version'];
}
}
Expand Down Expand Up @@ -527,7 +527,7 @@ private function get_checkout_cta( $api, $plan = null ) {
$plan->plugin_id,
$plan->pricing[0]->id,
$this->get_billing_cycle( $plan ),
$plan->has_trial(), // @phpstan-ignore-line
$plan->has_trial(),
( $has_valid_blog_id ? false : null )
);

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

return '<a class="button button-primary fs-checkout-button right" href="' . $addon_checkout_url . '" target="_parent">' .
esc_html( ! $plan->has_trial() ? // @phpstan-ignore-line
esc_html( ! $plan->has_trial() ?
(
$api->has_purchased_license ?
fs_text_inline( 'Purchase More', 'purchase-more', $api->slug ) :
Expand Down
5 changes: 2 additions & 3 deletions includes/managers/class-fs-cache-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ function get( $key, $default = null ) {
isset( $cache_entry->timestamp ) &&
is_numeric( $cache_entry->timestamp )
) {
return $cache_entry->result; // @phpstan-ignore-line

return $cache_entry->result;
}

return is_object( $default ) ? clone $default : $default;
Expand Down Expand Up @@ -324,4 +323,4 @@ function migrate_to_network() {
}

#endregion
}
}
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,33 @@ parameters:
-
message: '#PHPDoc tag @var above a method has no effect.#'
path: includes/class-freemius.php
-
message: '#Action callback returns bool but should not return anything.#'
path: includes/class-freemius.php
-
message: '#Variable \$site_ids in empty\(\) always exists and is always falsy.#'
path: includes/class-freemius.php
-
message: '#Variable \$new_user_licenses_map in empty\(\) always exists and is not falsy.#'
path: includes/class-freemius.php
-
message: '#Access to an undefined property#'
paths:
- start.php
- templates/debug.php
- templates/add-ons.php
- templates/plugin-info/features.php
- includes/class-freemius.php
- includes/fs-plugin-info-dialog.php
- includes/fs-essential-functions.php
- includes/class-fs-plugin-updater.php
- includes/managers/class-fs-cache-manager.php
-
message: '#will always evaluate to true#'
path: includes/class-fs-plugin-updater.php
-
message: '#Call to an undefined method object::has_trial\(\)#'
path: includes/fs-plugin-info-dialog.php
-
message: '#Variable \$VARS might not be defined#'
paths:
Expand Down
14 changes: 6 additions & 8 deletions templates/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@
) );
}

$payments = [];
$show_billing = ( ! $is_whitelabeled && ! $fs->apply_filters( 'hide_billing_and_payments_info', false ) );
if ( $show_billing ) {
$payments = $fs->_fetch_payments();

$show_billing = ( is_array( $payments ) && 0 < count( $payments ) );
$payments = $fs->_fetch_payments();
$show_billing = ( 0 < count( $payments ) );
}


$has_tabs = $fs->_add_tabs_before_content();

// Aliases.
Expand Down Expand Up @@ -137,8 +136,7 @@

$show_plan_row = true;
$show_license_row = is_object( $license );

$site_view_params = array();
$site_view_params = array();

if ( fs_is_network_admin() ) {
$sites = Freemius::get_sites();
Expand All @@ -157,7 +155,7 @@

$site_view_params[] = $view_params;

if ( is_object( $install ) ) {
if ( ! is_object( $install ) ) {
continue;
}

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

<?php
if ( $show_billing ) {
$view_params = array( 'id' => $VARS['id'], 'payments' => $payments ); // @phpstan-ignore-line
$view_params = array( 'id' => $VARS['id'], 'payments' => $payments );
fs_require_once_template( 'account/billing.php', $view_params );
fs_require_once_template( 'account/payments.php', $view_params );
}
Expand Down
8 changes: 6 additions & 2 deletions templates/account/partials/addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
$show_upgrade = false;
$is_whitelabeled = $VARS['is_whitelabeled'];

$version = '';
$plan_name = '';
$plan_title = '';

if ( is_object( $fs_addon ) ) {
$is_paying = $fs_addon->is_paying();
$user = $fs_addon->get_user();
Expand Down Expand Up @@ -158,11 +162,11 @@
<!--/ ID -->

<!-- Version -->
<td><?php echo $version; // @phpstan-ignore-line ?></td>
<td><?php echo $version; ?></td>
<!--/ Version -->

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

<!-- Expiration -->
Expand Down
10 changes: 3 additions & 7 deletions templates/add-ons.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@
}

$has_paid_plan = true;

if ( isset( $plan->trial_period ) ) {
$has_trial = ( is_numeric( $plan->trial_period ) && ( $plan->trial_period > 0 ) );
}

$min_price = 999999;
$has_trial = isset( $plan->trial_period ) && is_numeric( $plan->trial_period ) && $plan->trial_period > 0;
$min_price = 999999;
foreach ( $plan->pricing as $pricing ) {
$pricing = new FS_Pricing( $pricing );

Expand Down Expand Up @@ -501,4 +497,4 @@ function toggleDropdown( $dropdown, state ) {
'module_slug' => $slug,
'module_version' => $fs->get_plugin_version(),
);
fs_require_template( 'powered-by.php', $params );
fs_require_template( 'powered-by.php', $params );
Loading

0 comments on commit fe76177

Please sign in to comment.