Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-fix issues found by Psalm #7098

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions includes/3rd-party/themes/astra.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Enqueue Astra theme-specific Learning Mode styles.
*
* @return false|null
*/
function sensei_load_learning_mode_styles_for_astra_theme() {
$course_id = Sensei_Utils::get_current_course();
Expand Down
6 changes: 5 additions & 1 deletion includes/3rd-party/themes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
/**
* Don't load Learning Mode styles from Course theme.
*/
function sensei_disable_learning_mode_style_for_course_theme() {
function sensei_disable_learning_mode_style_for_course_theme(): void {
add_filter( 'course_learning_mode_load_styles', '__return_false' );
}

/**
* Enqueue Course theme-specific Learning Mode styles.
*
* @return false|null
*/
function sensei_load_learning_mode_style_for_course_theme() {
$course_id = Sensei_Utils::get_current_course();
Expand All @@ -30,6 +32,8 @@ function sensei_load_learning_mode_style_for_course_theme() {

/**
* Enqueue Course theme-specific Learning Mode styles in the admin for the Site Editor and Lesson Editor.
*
* @return void
*/
function sensei_admin_load_learning_mode_style_for_course_theme() {
$is_course_theme = 'course' === wp_get_theme()->get_template();
Expand Down
10 changes: 8 additions & 2 deletions includes/3rd-party/themes/divi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* It disables Yoast initialization when running the Divi preview in the editor.
* It avoids an existing conflict that prevents the preview from loading.
*/
function sensei_fix_divi_yoast_conflict() {
function sensei_fix_divi_yoast_conflict(): void {
if (
isset( $_GET['et_block_layout_preview'] ) && '1' === $_GET['et_block_layout_preview'] // phpcs:ignore WordPress.Security.NonceVerification.Recommended
&& 'lesson' === get_post_type()
Expand Down Expand Up @@ -57,7 +57,7 @@ function sensei_disable_divi_theme_builder( $layouts ) {
/**
* If learning mode is enabled for the current course we disable the Divi Theme Builder.
*/
function sensei_fix_divi_theme_builder_and_learning_mode_conflict() {
function sensei_fix_divi_theme_builder_and_learning_mode_conflict(): void {
$course_id = Sensei_Utils::get_current_course();
if ( ! is_null( $course_id ) && Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id ) ) {
add_filter( 'et_theme_builder_template_layouts', 'sensei_disable_divi_theme_builder', 11, 1 );
Expand All @@ -70,6 +70,8 @@ function sensei_fix_divi_theme_builder_and_learning_mode_conflict() {
* Disable the Divi excerpt logic for the Video learning mode template.
*
* This fixes an error generated by Divi when the Video learning mode template is used.
*
* @return void
*/
function sensei_fix_divi_learning_mode_video_template_excerpt() {
if (
Expand All @@ -92,6 +94,8 @@ function sensei_fix_divi_learning_mode_video_template_excerpt() {

/**
* Enqueue Divi theme-specific Learning Mode styles.
*
* @return false|null
*/
function sensei_load_learning_mode_style_for_divi_theme() {
$course_id = Sensei_Utils::get_current_course();
Expand All @@ -108,6 +112,8 @@ function sensei_load_learning_mode_style_for_divi_theme() {

/**
* Enqueue Divi theme-specific Learning Mode styles in the admin for the Site Editor and Lesson Editor.
*
* @return void
*/
function sensei_admin_load_learning_mode_style_for_divi_theme() {
$is_target_theme = 'divi' === strtolower( wp_get_theme()->get_template() );
Expand Down
2 changes: 1 addition & 1 deletion includes/3rd-party/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function sensei_woocommerce_prevent_admin_access( $prevent_access ) {
/**
* Show admin bar to users who can 'edit_courses'.
*/
function sensei_woocommerce_show_admin_bar() {
function sensei_woocommerce_show_admin_bar(): void {
if ( current_user_can( 'edit_courses' ) ) {
add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1 );
}
Expand Down
24 changes: 17 additions & 7 deletions includes/admin/class-sensei-admin-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ private function __construct() {

/**
* Initialize hooks.
*
* @return void
*/
public function init() {
if ( ! is_admin() ) {
Expand Down Expand Up @@ -201,6 +203,8 @@ protected function get_notices( $max_age = null ) {
* Output the admin notice.
*
* @access private
*
* @return void
*/
public function add_admin_notices() {
$screen_id = $this->get_screen_id();
Expand Down Expand Up @@ -230,7 +234,7 @@ public function add_admin_notices() {
* @param string $notice_id The unique notice ID.
* @param array $notice The notice configuration.
*/
private function add_admin_notice( $notice_id, $notice ) {
private function add_admin_notice( $notice_id, $notice ): void {
if ( empty( $notice['actions'] ) || ! is_array( $notice['actions'] ) ) {
$notice['actions'] = [];
}
Expand Down Expand Up @@ -299,9 +303,11 @@ private function add_admin_notice( $notice_id, $notice ) {
* @param string $screen_id The screen ID.
* @param int|null $max_age The max age (seconds) of the source data.
*
* @return array
* @return array[]
*
* @psalm-return array<array{message: mixed}>
*/
public function get_notices_to_display( $screen_id = null, $max_age = null ) {
public function get_notices_to_display( $screen_id = null, $max_age = null ): array {
$notices = [];
foreach ( $this->get_notices( $max_age ) as $notice_id => $notice ) {
$notice = $this->normalize_notice( $notice );
Expand Down Expand Up @@ -619,9 +625,11 @@ private function condition_check_plugin( array $allowed_plugins ) : bool {
/**
* Partial wrapper for for `get_plugins()` function. Filters out non-active plugins.
*
* @return array Key is basename of active plugins and value is version.
* @return array[] Key is basename of active plugins and value is version.
*
* @psalm-return array<array>
*/
protected function get_active_plugins() {
protected function get_active_plugins(): array {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
Expand All @@ -643,7 +651,7 @@ protected function get_active_plugins() {
*
* @return array
*/
private function normalize_notice( $notice ) {
private function normalize_notice( $notice ): array {
if ( ! isset( $notice['conditions'] ) || ! is_array( $notice['conditions'] ) ) {
$notice['conditions'] = [];
}
Expand Down Expand Up @@ -712,7 +720,7 @@ private function get_dismissed_notices( $is_user_notification ) {
* @param array $dismissed_notices Array of dismissed notices.
* @param bool $is_user_notification True if we are setting user notifications (vs site-wide notifications).
*/
private function save_dismissed_notices( $dismissed_notices, $is_user_notification ) {
private function save_dismissed_notices( $dismissed_notices, $is_user_notification ): void {
if ( $is_user_notification ) {
update_user_meta( get_current_user_id(), self::DISMISSED_NOTICES_USER_META, $dismissed_notices );
} else {
Expand All @@ -724,6 +732,8 @@ private function save_dismissed_notices( $dismissed_notices, $is_user_notificati
* Handle the dismissal of the notice.
*
* @access private
*
* @return void
*/
public function handle_notice_dismiss() {
check_ajax_referer( self::DISMISS_NOTICE_NONCE_ACTION, 'nonce' );
Expand Down
6 changes: 3 additions & 3 deletions includes/admin/class-sensei-editor-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function instance() {
/**
* Initializes the class.
*/
public function init() {
public function init(): void {
add_action( 'init', [ $this, 'register_post_metas' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
}
Expand All @@ -54,7 +54,7 @@ public function init() {
*
* @access private
*/
public function register_post_metas() {
public function register_post_metas(): void {
// A meta used to identify lessons created dynamically as new.
register_post_meta(
'lesson',
Expand All @@ -77,7 +77,7 @@ public function register_post_metas() {
*
* @access private
*/
public function enqueue_admin_scripts( $hook_suffix ) {
public function enqueue_admin_scripts( $hook_suffix ): void {
$post_type = get_post_type();
$post_id = get_the_ID();
$new_post = get_post_meta( $post_id, '_new_post', true );
Expand Down
7 changes: 4 additions & 3 deletions includes/admin/class-sensei-exit-survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public function __construct() {
/**
* Enqueues admin scripts when needed on different screens.
*
* @since 2.0.0
* @since 2.0.0
*
* @access private
*/
public function enqueue_admin_assets() {
public function enqueue_admin_assets(): void {
$screen = get_current_screen();
if ( in_array( $screen->id, [ 'plugins', 'plugins-network' ], true ) ) {
Sensei()->assets->enqueue( 'sensei-admin-exit-survey', 'admin/exit-survey/index.js', [], true );
Expand All @@ -52,7 +53,7 @@ public function enqueue_admin_assets() {
/**
* Save feedback from exit survey AJAX request.
*/
public function save_exit_survey() {
public function save_exit_survey(): void {
check_ajax_referer( 'sensei_exit_survey' );

$feedback = [
Expand Down
38 changes: 25 additions & 13 deletions includes/admin/class-sensei-extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,23 @@ private function __construct() {}
* Initializes the class and adds all filters and actions related to the extension directory.
*
* @since 2.0.0
*
* @deprecated 4.8.0
*/
public function init() {
public function init(): void {
_deprecated_function( __METHOD__, '4.8.0' );
}

/**
* Enqueues admin scripts when needed on different screens.
*
* @since 2.0.0
* @since 2.0.0
*
* @access private
*
* @deprecated 4.8.0
*/
public function enqueue_admin_assets() {
public function enqueue_admin_assets(): void {
_deprecated_function( __METHOD__, '4.8.0' );
}

Expand Down Expand Up @@ -141,12 +144,15 @@ function( $extension ) use ( $slug ) {
*
* @since 4.8.0
*
* @param string $type Product type ('plugin' or 'theme').
* @param string $category Category to fetch (null = all).
* @param string $additional_query_args Additional query arguments.
* @return array
* @param string $type Product type ('plugin' or 'theme').
* @param string $category Category to fetch (null = all).
* @param string $additional_query_args Additional query arguments.
*
* @return (array|mixed)[]
*
* @psalm-return array<array|mixed>
*/
public function get_extensions_and_woocommerce( $type = null, $category = null, $additional_query_args = [] ) {
public function get_extensions_and_woocommerce( $type = null, $category = null, $additional_query_args = [] ): array {
$extensions = $this->get_extensions( $type, $category, $additional_query_args );

// Add WooCommerce.
Expand Down Expand Up @@ -226,11 +232,14 @@ function( $theme ) {
* Get extensions page layout.
*
* @since 3.11.0
*
* @deprecated 4.14.0
*
* @return array
*
* @psalm-return array<empty, empty>
*/
public function get_layout() {
public function get_layout(): array {
_deprecated_function( __METHOD__, '4.14.0' );

return [];
Expand Down Expand Up @@ -268,23 +277,26 @@ function( $extension ) use ( $only_woo ) {
/**
* Adds the menu item for the Home page.
*
* @since 4.8.0
* @since 4.8.0
*
* @access private
*
* @deprecated 4.8.0
*/
public function add_admin_menu_item() {
public function add_admin_menu_item(): void {
_deprecated_function( __METHOD__, '4.8.0' );
}

/**
* Renders the extensions page.
*
* @since 2.0.0
* @since 2.0.0
*
* @access private
*
* @deprecated 4.8.0
*/
public function render() {
public function render(): void {
_deprecated_function( __METHOD__, '4.8.0' );
}

Expand Down
18 changes: 10 additions & 8 deletions includes/admin/class-sensei-home.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function get_rest_api_controller( $namespace ) {
*
* @since 4.8.0
*/
public function init() {
public function init(): void {
$this->notices->init();

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
Expand All @@ -136,9 +136,10 @@ public function init() {
* Enqueues admin scripts when needed on different screens.
*
* @since 4.8.0
*
* @access private
*/
public function enqueue_admin_assets() {
public function enqueue_admin_assets(): void {
$screen = get_current_screen();

if ( self::SCREEN_ID === $screen->id ) {
Expand All @@ -156,7 +157,7 @@ public function enqueue_admin_assets() {
*
* @since 4.8.0
*/
private function localize_script() {
private function localize_script(): void {
$data = array(
'connectUrl' => add_query_arg(
array(
Expand Down Expand Up @@ -216,11 +217,11 @@ private function get_notices_count() {
/**
* Adds the menu item for the Home page.
*
* @since 4.8.0
* @since 4.8.0
*
* @access private
*/
public function add_admin_menu_item() {
public function add_admin_menu_item(): void {
$menu_cap = Sensei_Admin::get_top_menu_capability();

$notices_html = '';
Expand All @@ -244,18 +245,19 @@ public function add_admin_menu_item() {
/**
* Renders Sensei Home.
*
* @since 4.8.0
* @since 4.8.0
*
* @access private
*/
public function render() {
public function render(): void {
require __DIR__ . '/views/html-admin-page-home.php';
}
/**
* Handle tasks dismissal.
*
* @access private
*/
public function handle_tasks_dismiss() {
public function handle_tasks_dismiss(): void {
check_ajax_referer( self::DISMISS_TASKS_NONCE_ACTION );

if ( ! current_user_can( 'manage_options' ) ) {
Expand Down
Loading
Loading