Skip to content

Commit 37ed17d

Browse files
committed
[static-analysis] Fix php errors from static analysis
1 parent a19788f commit 37ed17d

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
@@ -996,7 +996,7 @@ private static function migrate_install_plan_to_plan_id( FS_Storage $storage, $b
996996

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

10021002
unset( $install->plan );
@@ -1891,7 +1891,7 @@ private function clear_module_main_file_cache( $store_prev_path = true ) {
18911891
$plugin_main_file = clone $this->_storage->plugin_main_file;
18921892

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

18961896
// Clear cached path.
18971897
unset( $plugin_main_file->path );
@@ -5960,9 +5960,6 @@ function is_org_repo_compliant() {
59605960
private function get_cron_data( $name ) {
59615961
$this->_logger->entrance( $name );
59625962

5963-
/**
5964-
* @var object $cron_data
5965-
*/
59665963
return $this->_storage->get( "{$name}_cron", null );
59675964
}
59685965

@@ -8594,7 +8591,6 @@ function skip_connection( $network_or_blog_ids = false ) {
85948591
* @since 2.0.0
85958592
*
85968593
* @param int|null $blog_id
8597-
* @param bool $send_skip
85988594
*/
85998595
private function skip_site_connection( $blog_id = null ) {
86008596
$this->_logger->entrance();
@@ -8628,7 +8624,7 @@ private function update_plugin_version_event() {
86288624
* @author Vova Feldman (@svovaf)
86298625
* @since 2.0.0
86308626
*
8631-
* @param array [string]array $plugins
8627+
* @param string[] $plugins
86328628
*
86338629
* @return string
86348630
*/
@@ -9043,7 +9039,7 @@ private function get_install_data_for_api(
90439039
* @author Vova Feldman (@svovaf)
90449040
* @since 2.0.0
90459041
*
9046-
* @param string[] string $override
9042+
* @param string[] $override
90479043
* @param bool $only_diff
90489044
* @param bool $is_keepalive
90499045
* @param bool $include_plugins Since 1.1.8 by default include plugin changes.
@@ -9230,7 +9226,7 @@ private function get_installs_data_for_api(
92309226
*
92319227
* @param array $site
92329228
* @param FS_Site $install
9233-
* @param string[] string $override
9229+
* @param string[] $override
92349230
*
92359231
* @return array
92369232
*/
@@ -9352,7 +9348,7 @@ function send_clone_resolution_update( $resolution_type, $clone_context_install
93529348
* @author Vova Feldman (@svovaf)
93539349
* @since 1.0.9
93549350
*
9355-
* @param string[] string $override
9351+
* @param string[] $override
93569352
* @param bool $flush
93579353
* @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.
93589354
*
@@ -9425,7 +9421,7 @@ private function send_install_update( $override = array(), $flush = false, $is_t
94259421
* @author Vova Feldman (@svovaf)
94269422
* @since 2.0.0
94279423
*
9428-
* @param string[] string $override
9424+
* @param string[] $override
94299425
* @param bool $flush
94309426
* @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.
94319427
*
@@ -9512,7 +9508,7 @@ private function maybe_sync_install_user() {
95129508
* @author Vova Feldman (@svovaf)
95139509
* @since 1.0.9
95149510
*
9515-
* @param string[] string $override
9511+
* @param string[] $override
95169512
* @param bool $flush
95179513
*/
95189514
function sync_install( $override = array(), $flush = false ) {
@@ -9541,7 +9537,7 @@ function sync_install( $override = array(), $flush = false ) {
95419537
* @author Vova Feldman (@svovaf)
95429538
* @since 1.0.9
95439539
*
9544-
* @param string[] string $override
9540+
* @param string[] $override
95459541
* @param bool $flush
95469542
*/
95479543
private function sync_installs( $override = array(), $flush = false ) {
@@ -19614,7 +19610,7 @@ function has_filter( $tag, $function_to_check = false ) {
1961419610
* @author Vova Feldman (@svovaf)
1961519611
* @since 1.1.6
1961619612
*
19617-
* @param string[] string $key_value
19613+
* @param string[] $key_value
1961819614
*
1961919615
* @uses fs_override_i18n()
1962019616
*/
@@ -22575,8 +22571,8 @@ private function complete_change_owner() {
2257522571
* @author Leo Fajardo (@leorw)
2257622572
* @since 2.3.2
2257722573
*
22578-
* @param number $user_id
22579-
* @param array[string]number $install_ids_by_slug_map
22574+
* @param number $user_id
22575+
* @param string[]|int[] $install_ids_by_slug_map
2258022576
*
2258122577
*/
2258222578
private function complete_ownership_change_by_license( $user_id, $install_ids_by_slug_map ) {
@@ -25777,9 +25773,6 @@ function _maybe_show_gdpr_admin_notice() {
2577725773
return;
2577825774
}
2577925775

25780-
/**
25781-
* @var $current_wp_user WP_User
25782-
*/
2578325776
$current_wp_user = self::_get_current_wp_user();
2578425777

2578525778
/**

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)