Skip to content

Commit 999474d

Browse files
committed
[static-analysis] Fix php errors from static analysis
1 parent d2c5058 commit 999474d

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 );
@@ -1884,7 +1884,7 @@ private function clear_module_main_file_cache( $store_prev_path = true ) {
18841884
$plugin_main_file = clone $this->_storage->plugin_main_file;
18851885

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

18891889
// Clear cached path.
18901890
unset( $plugin_main_file->path );
@@ -5953,9 +5953,6 @@ function is_org_repo_compliant() {
59535953
private function get_cron_data( $name ) {
59545954
$this->_logger->entrance( $name );
59555955

5956-
/**
5957-
* @var object $cron_data
5958-
*/
59595956
return $this->_storage->get( "{$name}_cron", null );
59605957
}
59615958

@@ -8587,7 +8584,6 @@ function skip_connection( $network_or_blog_ids = false ) {
85878584
* @since 2.0.0
85888585
*
85898586
* @param int|null $blog_id
8590-
* @param bool $send_skip
85918587
*/
85928588
private function skip_site_connection( $blog_id = null ) {
85938589
$this->_logger->entrance();
@@ -8621,7 +8617,7 @@ private function update_plugin_version_event() {
86218617
* @author Vova Feldman (@svovaf)
86228618
* @since 2.0.0
86238619
*
8624-
* @param array [string]array $plugins
8620+
* @param string[] $plugins
86258621
*
86268622
* @return string
86278623
*/
@@ -9036,7 +9032,7 @@ private function get_install_data_for_api(
90369032
* @author Vova Feldman (@svovaf)
90379033
* @since 2.0.0
90389034
*
9039-
* @param string[] string $override
9035+
* @param string[] $override
90409036
* @param bool $only_diff
90419037
* @param bool $is_keepalive
90429038
* @param bool $include_plugins Since 1.1.8 by default include plugin changes.
@@ -9223,7 +9219,7 @@ private function get_installs_data_for_api(
92239219
*
92249220
* @param array $site
92259221
* @param FS_Site $install
9226-
* @param string[] string $override
9222+
* @param string[] $override
92279223
*
92289224
* @return array
92299225
*/
@@ -9345,7 +9341,7 @@ function send_clone_resolution_update( $resolution_type, $clone_context_install
93459341
* @author Vova Feldman (@svovaf)
93469342
* @since 1.0.9
93479343
*
9348-
* @param string[] string $override
9344+
* @param string[] $override
93499345
* @param bool $flush
93509346
* @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.
93519347
*
@@ -9418,7 +9414,7 @@ private function send_install_update( $override = array(), $flush = false, $is_t
94189414
* @author Vova Feldman (@svovaf)
94199415
* @since 2.0.0
94209416
*
9421-
* @param string[] string $override
9417+
* @param string[] $override
94229418
* @param bool $flush
94239419
* @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.
94249420
*
@@ -9505,7 +9501,7 @@ private function maybe_sync_install_user() {
95059501
* @author Vova Feldman (@svovaf)
95069502
* @since 1.0.9
95079503
*
9508-
* @param string[] string $override
9504+
* @param string[] $override
95099505
* @param bool $flush
95109506
*/
95119507
function sync_install( $override = array(), $flush = false ) {
@@ -9534,7 +9530,7 @@ function sync_install( $override = array(), $flush = false ) {
95349530
* @author Vova Feldman (@svovaf)
95359531
* @since 1.0.9
95369532
*
9537-
* @param string[] string $override
9533+
* @param string[] $override
95389534
* @param bool $flush
95399535
*/
95409536
private function sync_installs( $override = array(), $flush = false ) {
@@ -19575,7 +19571,7 @@ function has_filter( $tag, $function_to_check = false ) {
1957519571
* @author Vova Feldman (@svovaf)
1957619572
* @since 1.1.6
1957719573
*
19578-
* @param string[] string $key_value
19574+
* @param string[] $key_value
1957919575
*
1958019576
* @uses fs_override_i18n()
1958119577
*/
@@ -22515,8 +22511,8 @@ private function complete_change_owner() {
2251522511
* @author Leo Fajardo (@leorw)
2251622512
* @since 2.3.2
2251722513
*
22518-
* @param number $user_id
22519-
* @param array[string]number $install_ids_by_slug_map
22514+
* @param number $user_id
22515+
* @param string[]|int[] $install_ids_by_slug_map
2252022516
*
2252122517
*/
2252222518
private function complete_ownership_change_by_license( $user_id, $install_ids_by_slug_map ) {
@@ -25702,9 +25698,6 @@ function _maybe_show_gdpr_admin_notice() {
2570225698
return;
2570325699
}
2570425700

25705-
/**
25706-
* @var $current_wp_user WP_User
25707-
*/
2570825701
$current_wp_user = self::_get_current_wp_user();
2570925702

2571025703
/**

includes/class-fs-plugin-updater.php

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

11161116
// Fetch as much as possible info from local files.
11171117
$plugin_local_data = $this->_fs->get_plugin_data();
1118-
$data->name = $plugin_local_data['Name'];
1119-
$data->author = $plugin_local_data['Author'];
1120-
$data->sections = array(
1121-
'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.',
1122-
);
1118+
$data->name = $plugin_local_data['Name']; // @phpstan-ignore-line
1119+
$data->author = $plugin_local_data['Author']; // @phpstan-ignore-line
1120+
$data->sections = array( 'description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.' ); // @phpstan-ignore-line
11231121

11241122
// @todo Store extra plugin info on Freemius or parse readme.txt markup.
11251123
/*$info = $this->_fs->get_api_site_scope()->call('/information.json');
@@ -1143,18 +1141,18 @@ function plugins_api_filter( $data, $action = '', $args = null ) {
11431141
$data->name = $addon->title . ' ' . $this->_fs->get_text_inline( 'Add-On', 'addon' );
11441142
$data->slug = $addon->slug;
11451143
$data->url = WP_FS__ADDRESS;
1146-
$data->package = $new_version->url;
1144+
$data->package = $new_version->url; // @phpstan-ignore-line
11471145
}
11481146

11491147
if ( ! $plugin_in_repo ) {
1150-
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
1151-
$data->requires = $new_version->requires_platform_version;
1152-
$data->requires_php = $new_version->requires_programming_language_version;
1153-
$data->tested = $new_version->tested_up_to_version;
1148+
$data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created; // @phpstan-ignore-line
1149+
$data->requires = $new_version->requires_platform_version; // @phpstan-ignore-line
1150+
$data->requires_php = $new_version->requires_programming_language_version; // @phpstan-ignore-line
1151+
$data->tested = $new_version->tested_up_to_version; // @phpstan-ignore-line
11541152
}
11551153

11561154
$data->version = $new_version->version;
1157-
$data->download_link = $new_version->url;
1155+
$data->download_link = $new_version->url; // @phpstan-ignore-line
11581156

11591157
if ( isset( $new_version->readme ) && is_object( $new_version->readme ) ) {
11601158
$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)