diff --git a/includes/abstracts/class-wpum-form.php b/includes/abstracts/class-wpum-form.php index 05c059e2..cc596c37 100644 --- a/includes/abstracts/class-wpum-form.php +++ b/includes/abstracts/class-wpum-form.php @@ -470,7 +470,7 @@ protected function get_parsed_id( $name, $nicename, $field ) { if ( ! empty( $nicename ) ) { return str_replace( ' ', '_', strtolower( $nicename ) ); - } elseif ( empty( $nicename ) && $field->get_meta( 'user_meta_key' ) ) { + } elseif ( $field->get_meta( 'user_meta_key' ) ) { return $field->get_meta( 'user_meta_key' ); } diff --git a/includes/abstracts/class-wpum-shortcode-generator.php b/includes/abstracts/class-wpum-shortcode-generator.php index 1b2b18dd..4703f822 100644 --- a/includes/abstracts/class-wpum-shortcode-generator.php +++ b/includes/abstracts/class-wpum-shortcode-generator.php @@ -240,7 +240,7 @@ protected function generate_listbox( $field ) { /** * Generate a textbox for the window. * - * @param [type] $field + * @param array $field * * @return array|false */ @@ -257,6 +257,7 @@ protected function generate_textbox( $field ) { 'value' => '', 'classes' => '', ), $field ); + if ( $this->validate( $field ) ) { return array_filter( $textbox, array( $this, 'return_textbox_value' ) ); } diff --git a/includes/abstracts/class-wpum-wp-db-table.php b/includes/abstracts/class-wpum-wp-db-table.php index 75ddf77b..51b6f673 100644 --- a/includes/abstracts/class-wpum-wp-db-table.php +++ b/includes/abstracts/class-wpum-wp-db-table.php @@ -72,7 +72,7 @@ abstract class WPUM_WP_DB_Table { */ protected $charset_collation = ''; /** - * @var WPDB Database object (usually $GLOBALS['wpdb']) + * @var \wpdb Database object (usually $GLOBALS['wpdb']) */ protected $db = false; /** Methods ***************************************************************/ diff --git a/includes/actions.php b/includes/actions.php index 4611f28e..3d4f58cb 100644 --- a/includes/actions.php +++ b/includes/actions.php @@ -224,6 +224,7 @@ function wpum_restrict_wp_profile() { $profile_redirect = wpum_get_option( 'backend_profile_redirect' ); + // @phpstan-ignore-next-line IS_PROFILE_PAGE is defined in wp-admin/profile.php if ( ! current_user_can( 'administrator' ) && IS_PROFILE_PAGE && $profile_redirect ) { wp_safe_redirect( esc_url( get_permalink( $profile_redirect[0] ) ) ); exit; diff --git a/includes/admin/class-wpum-permalinks-settings.php b/includes/admin/class-wpum-permalinks-settings.php index 9e7a8fbf..a6a9beba 100644 --- a/includes/admin/class-wpum-permalinks-settings.php +++ b/includes/admin/class-wpum-permalinks-settings.php @@ -65,7 +65,7 @@ public function display_settings() { -

not using "default" permalinks above.', 'wp-user-manager' ); ?>

+

not using "default" permalinks above.', 'wp-user-manager' ); ?>

diff --git a/includes/admin/class-wpum-user-table.php b/includes/admin/class-wpum-user-table.php index 0c307f46..559d8a4f 100644 --- a/includes/admin/class-wpum-user-table.php +++ b/includes/admin/class-wpum-user-table.php @@ -127,14 +127,14 @@ public function handle_users_role_bulk_add() { $role = sanitize_text_field( wp_unslash( $_REQUEST['wpum-add-role-bottom'] ) ); } - $m_role = wpum_get_role( $role ); - $roles = array_column( wpum_get_roles( false, true ), 'value' ); + $roles = array_column( wpum_get_roles( false, true ), 'value' ); if ( empty( $role ) || ! in_array( $role, $roles, true ) ) { return; } - $count = 0; + $m_role = wpum_get_role( $role ); + $count = 0; $users = filter_input( INPUT_GET, 'users', FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY ); if ( empty( $users ) ) { diff --git a/includes/shortcodes/shortcodes.php b/includes/shortcodes/shortcodes.php index fc4043df..eec53529 100644 --- a/includes/shortcodes/shortcodes.php +++ b/includes/shortcodes/shortcodes.php @@ -776,7 +776,7 @@ function wpum_directory( $atts, $content = null ) { } // Exclude users if anything specified. - if ( $excluded_users && ! empty( $excluded_users ) ) { + if ( ! empty( $excluded_users ) ) { $excluded_users = trim( str_replace( ' ', '', $excluded_users ) ); $args['exclude'] = explode( ',', $excluded_users ); } diff --git a/includes/updates/WPUM_EDD_SL_Plugin_Updater.php b/includes/updates/WPUM_EDD_SL_Plugin_Updater.php index 2c07c50b..91b34d59 100755 --- a/includes/updates/WPUM_EDD_SL_Plugin_Updater.php +++ b/includes/updates/WPUM_EDD_SL_Plugin_Updater.php @@ -239,7 +239,7 @@ public function show_update_notification( $file, $plugin ) { // build a plugin list row, with update notification $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); - # '; echo '
+ //
echo '
'; echo '
'; diff --git a/includes/updates/class-wpum-license.php b/includes/updates/class-wpum-license.php index e084e1d2..48109c7b 100644 --- a/includes/updates/class-wpum-license.php +++ b/includes/updates/class-wpum-license.php @@ -242,7 +242,7 @@ public function handle_deactivate_license() { * @param string $license * @param string $site_url * - * @return mixed|WP_Error|null + * @return object|WP_Error|null */ protected function api_request( $endpoint, $license, $site_url ) { $api_params = array( @@ -276,7 +276,7 @@ protected function api_request( $endpoint, $license, $site_url ) { * @param string $license * @param string $site_url * - * @return mixed|WP_Error|null + * @return object|WP_Error|null */ protected function activate_license( $license, $site_url ) { return $this->api_request( 'activate_license', $license, $site_url ); @@ -285,7 +285,7 @@ protected function activate_license( $license, $site_url ) { /** * @param string $site_url * - * @return mixed|WP_Error|null + * @return object|WP_Error|null */ protected function deactivate_license( $site_url ) { return $this->api_request( 'deactivate_license', $this->license, $site_url ); @@ -325,7 +325,7 @@ private function get_license_deactivation_url() { } /** - * @param array $license_data + * @param object $license_data * * @return array */ @@ -346,7 +346,7 @@ protected function prepare_license_data( $license_data ) { 'status' => $license_data->license, ); - if ( isset( $license_data->success ) && $license_data->success ) { + if ( isset( $license_data->success ) && $license_data->success && isset( $license_data->expires ) ) { $data['expires'] = $license_data->expires; } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 23cca912..bda192b4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,9 +3,31 @@ includes: parameters: scanFiles: - vendor/htmlburger/carbon-fields/core/functions.php + - vendor/wpbp/widgets-helper/class.wph-widget.php + bootstrapFiles: + - tests/phpstan/bootstrap.php + dynamicConstantNames: + - COOKIEHASH + - COOKIE_DOMAIN #level: 5 - level: 0 + level: 2 paths: - wp-user-manager.php - uninstall.php - includes/ + ignoreErrors: + # TDP docblock problem + - + message: '#^Result of static method TDP\\WP_Notice::instance\(\) \(void\) is used\.$#' + path: includes/class-wp-user-manager.php + count: 1 + # `new static` in non-final class + - + message: '#^Unsafe usage of new static\(\)\.$#' + path: includes/roles/class-wpum-collection.php + count: 1 + # Carbon Fields has general Container return type + - + message: '#^Call to an undefined method Carbon_Fields\\Container\\Container::set_page_parent\(\)\.$#' + path: includes/updates/class-wpum-updater-settings.php + count: 1 diff --git a/tests/phpstan/bootstrap.php b/tests/phpstan/bootstrap.php new file mode 100644 index 00000000..e4df4422 --- /dev/null +++ b/tests/phpstan/bootstrap.php @@ -0,0 +1,8 @@ +