Skip to content

Commit a13fc40

Browse files
authored
Merge pull request #7650 from Automattic/fix/deprecation-notices
Fix deprecation notices on PHP 8.2
2 parents 53dbffa + 6a2ac9b commit a13fc40

30 files changed

+207
-25
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
strategy:
5656
fail-fast: false
5757
matrix:
58-
php: [7.4, 8.1]
58+
php: [7.4, 8.2]
5959
steps:
6060
- name: Download Build Artifact
6161
uses: actions/download-artifact@v3

.github/workflows/php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
matrix:
6060
wp: ['latest']
6161
wpmu: [0]
62-
php: ['7.4', '8.0']
62+
php: ['7.4', '8.2']
6363
include:
6464
- php: 7.4
6565
wp: '6.1'

changelog/fix-deprecation-notice-on-question-edit-screen

-4
This file was deleted.

changelog/fix-deprecation-notice-on-reports-screen

-4
This file was deleted.

changelog/fix-deprecation-notices

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Deprecation notices on PHP 8.2

includes/admin/class-sensei-learners-admin-bulk-actions-view.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ private function get_learner_courses_html( $user_id ) {
490490
$more_button = '';
491491

492492
foreach ( $courses as $course ) {
493-
$html_items[] = '<a href="' . esc_url( $this->controller->get_learner_management_course_url( $course->ID ) ) .
493+
$html_items[] = '<a href="' . esc_url( (string) $this->controller->get_learner_management_course_url( $course->ID ) ) .
494494
'" class="sensei-students__enrolled-course" data-course-id="' . esc_attr( $course->ID ) . '">' .
495495
esc_html( $course->post_title ) .
496496
'</a>';

includes/class-sensei-lesson.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4804,7 +4804,7 @@ public static function course_signup_link() {
48044804
* @return {bool} Whether to show the course sign up notice.
48054805
*/
48064806
if ( apply_filters( 'sensei_lesson_show_course_signup_notice', $show_course_signup_notice, $course_id ) ) {
4807-
$course_link = '<a href="' . esc_url( Sensei()->lesson->get_take_course_url( $course_id ) ) . '" title="' . esc_attr__( 'Sign Up', 'sensei-lms' ) . '">';
4807+
$course_link = '<a href="' . esc_url( (string) Sensei()->lesson->get_take_course_url( $course_id ) ) . '" title="' . esc_attr__( 'Sign Up', 'sensei-lms' ) . '">';
48084808
$course_link .= esc_html__( 'course', 'sensei-lms' );
48094809
$course_link .= '</a>';
48104810

includes/class-sensei-quiz.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use Sensei\Internal\Student_Progress\Quiz_Progress\Models\Quiz_Progress_Interface;
4-
use Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Quiz_Progress_Repository_Factory;
54

65
if ( ! defined( 'ABSPATH' ) ) {
76
exit; // Exit if accessed directly
@@ -1335,7 +1334,7 @@ public function get_user_answers_feedback( $lesson_id, $user_id = 0 ) {
13351334

13361335
foreach ( $encoded_feedback as $question_id => $feedback ) {
13371336

1338-
$answers_feedback[ $question_id ] = base64_decode( $feedback );
1337+
$answers_feedback[ $question_id ] = base64_decode( (string) $feedback );
13391338

13401339
}
13411340

includes/course-theme/class-sensei-course-theme-styles.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private static function get_property_value( $value ) {
203203
);
204204
$value = "var(--wp--$unwrapped_name)";
205205
} elseif ( preg_match( '/^[a-z0-9-]+$/i', $value ) ) {
206-
$value = "var(--wp--preset--color--${value})";
206+
$value = "var(--wp--preset--color--{$value})";
207207
}
208208

209209
return $value;

includes/data-port/class-sensei-data-port-utilities.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private static function create_term( $term_name, $taxonomy_name, $teacher_user_i
402402
*
403403
* @return array|string[]
404404
*/
405-
public static function split_list_safely( $str_list, $remove_quotes = false ) {
405+
public static function split_list_safely( string $str_list, bool $remove_quotes = false ) {
406406
if ( empty( trim( $str_list ) ) ) {
407407
return [];
408408
}

includes/data-port/models/class-sensei-import-question-model.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private function get_taxonomy_terms() {
352352

353353
$taxonomy_terms[ Sensei_Data_Port_Question_Schema::TAXONOMY_QUESTION_CATEGORY ] = [];
354354

355-
$category_list = Sensei_Data_Port_Utilities::split_list_safely( $this->get_value( Sensei_Data_Port_Question_Schema::COLUMN_CATEGORIES ), true );
355+
$category_list = Sensei_Data_Port_Utilities::split_list_safely( (string) $this->get_value( Sensei_Data_Port_Question_Schema::COLUMN_CATEGORIES ), true );
356356
if ( ! empty( $category_list ) ) {
357357
foreach ( $category_list as $category ) {
358358
$category_term = Sensei_Data_Port_Utilities::get_term( $category, Sensei_Data_Port_Question_Schema::TAXONOMY_QUESTION_CATEGORY );

includes/internal/emails/class-email-list-table.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
namespace Sensei\Internal\Emails;
99

1010
use Sensei_List_Table;
11-
use WP_Post;
12-
use WP_Query;
1311

1412
if ( ! defined( 'ABSPATH' ) ) {
1513
exit;
@@ -130,7 +128,7 @@ protected function get_row_data( $post ) {
130128
$description = $is_available ?
131129
sprintf(
132130
'<strong><a href="%1$s" class="row-title">%2$s</a></strong>%3$s',
133-
esc_url( get_edit_post_link( $post ) ),
131+
esc_url( (string) get_edit_post_link( $post ) ),
134132
get_post_meta( $post->ID, '_sensei_email_description', true ),
135133
$this->row_actions( $actions )
136134
) : sprintf(

includes/lib/usage-tracking/class-usage-tracking-base.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private function send_tracks_request( $event, $properties = array(), $event_time
263263
$p = array();
264264

265265
foreach ( $properties as $key => $value ) {
266-
$p[] = rawurlencode( $key ) . '=' . rawurlencode( $value );
266+
$p[] = rawurlencode( $key ) . '=' . rawurlencode( (string) $value );
267267
}
268268

269269
$pixel .= '?' . implode( '&', $p ) . '&_=_'; // EOF marker.

includes/lib/usage-tracking/tests/test-class-usage-tracking.php

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class Sensei_Base_Usage_Tracking_Test extends WP_UnitTestCase {
2121
private $event_counts = array();
2222
private $track_http_request = array();
2323

24+
/**
25+
* Usage tracking test subclass instance.
26+
*
27+
* @var Usage_Tracking_Test_Subclass
28+
*/
29+
private $usage_tracking;
30+
2431
public function setUp(): void {
2532
parent::setUp();
2633
// Update the class name here to match the Usage Tracking class.

includes/rest-api/class-sensei-rest-api-course-progress-controller.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Sensei_REST_API_Course_Progress_Controller extends \WP_REST_Controller {
3535
*
3636
* @param string $namespace Routes namespace.
3737
*/
38-
public function __construct( $namespace ) {
38+
public function __construct( $namespace ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound -- The variable name if defined in the WP_REST_Controller class.
3939
$this->namespace = $namespace;
4040
}
4141

@@ -74,6 +74,7 @@ public function batch_delete_items( WP_REST_Request $request ) {
7474
$student = new WP_User( $student_id );
7575
$result[ $student_id ] = false;
7676
if ( $student->exists() ) {
77+
$result[ $student_id ] = array();
7778
foreach ( $course_ids as $course_id ) {
7879
$result[ $student_id ][ $course_id ] = false;
7980
if ( Sensei_Utils::has_started_course( $course_id, $student_id ) ) {
@@ -83,7 +84,7 @@ public function batch_delete_items( WP_REST_Request $request ) {
8384
}
8485
}
8586

86-
return new WP_REST_Response( $result, WP_HTTP::OK );
87+
return new WP_REST_Response( $result, WP_Http::OK );
8788
}
8889

8990
/**

includes/rest-api/class-sensei-rest-api-course-students-controller.php

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function batch_create_items( WP_REST_Request $request ) {
8080
$user = new WP_User( $user_id );
8181
$result[ $user_id ] = false;
8282
if ( $user->exists() ) {
83+
$result[ $user_id ] = array();
8384
foreach ( $course_ids as $course_id ) {
8485
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
8586
$result[ $user_id ][ $course_id ] = $course_enrolment->enrol( $user_id );

phpunit.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
9+
convertDeprecationsToExceptions="true"
910
verbose="true"
1011
>
1112
<php>

tests/framework/factories/class-sensei-factory.php

+23
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,64 @@ class Sensei_Factory extends WP_UnitTest_Factory {
4545
protected $basic_test_question_ids;
4646

4747
/**
48+
* Course factory.
49+
*
4850
* @var WP_UnitTest_Factory_For_Course
4951
*/
5052
public $course;
5153

5254
/**
55+
* Lesson factory.
56+
*
5357
* @var WP_UnitTest_Factory_For_Lesson
5458
*/
5559
public $lesson;
5660

5761
/**
62+
* Quiz factory.
63+
*
5864
* @var WP_UnitTest_Factory_For_Quiz
5965
*/
6066
public $quiz;
6167

6268
/**
69+
* Question factory.
70+
*
6371
* @var WP_UnitTest_Factory_For_Question
6472
*/
6573
public $question;
6674

6775
/**
76+
* Multiple question factory.
77+
*
6878
* @var WP_UnitTest_Factory_For_Multiple_Question
6979
*/
7080
public $multiple_question;
7181

7282
/**
83+
* Module factory.
84+
*
7385
* @var WP_UnitTest_Factory_For_Module
7486
*/
7587
public $module;
7688

7789
/**
90+
* Question category factory.
91+
*
7892
* @var WP_UnitTest_Factory_For_Question_Category
7993
*/
8094
public $question_category;
8195

8296
/**
97+
* Course category factory.
98+
*
99+
* @var Sensei_UnitTest_Factory_For_Course_Category
100+
*/
101+
public $course_category;
102+
103+
/**
104+
* Message factory.
105+
*
83106
* @var WP_UnitTest_Factory_For_Message
84107
*/
85108
public $message;

tests/framework/trait-sensei-hpps-helpers.php

+43
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Using PHPUnit conventions.
9+
// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
910

1011
use Sensei\Internal\Quiz_Submission\Answer\Repositories\Answer_Repository_Factory;
1112
use Sensei\Internal\Quiz_Submission\Grade\Repositories\Grade_Repository_Factory;
@@ -25,6 +26,48 @@
2526
* @since 4.20.0
2627
*/
2728
trait Sensei_HPPS_Helpers {
29+
/**
30+
* Course progress repository.
31+
*
32+
* @var \Sensei\Internal\Student_Progress\Course_Progress\Repositories\Course_Progress_Repository_Interface
33+
*/
34+
private $_course_progress_repository;
35+
36+
/**
37+
* Lesson progress repository.
38+
*
39+
* @var \Sensei\Internal\Student_Progress\Lesson_Progress\Repositories\Lesson_Progress_Repository_Interface
40+
*/
41+
private $_lesson_progress_repository;
42+
43+
/**
44+
* Quiz repository.
45+
*
46+
* @var \Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Quiz_Progress_Repository_Interface
47+
*/
48+
private $_quiz_progress_repository;
49+
50+
/**
51+
* Submission repository.
52+
*
53+
* @var \Sensei\Internal\Quiz_Submission\Submission\Repositories\Submission_Repository_Interface
54+
*/
55+
private $_quiz_submission_repository;
56+
57+
/**
58+
* Answer repository.
59+
*
60+
* @var \Sensei\Internal\Quiz_Submission\Answer\Repositories\Answer_Repository_Interface
61+
*/
62+
private $_quiz_answer_repository;
63+
64+
/**
65+
* Grade repository.
66+
*
67+
* @var \Sensei\Internal\Quiz_Submission\Grade\Repositories\Grade_Repository_Interface
68+
*/
69+
private $_quiz_grade_repository;
70+
2871
private function enable_hpps_tables_repository() {
2972
Sensei()->settings->settings['experimental_progress_storage_repository'] = Progress_Storage_Settings::TABLES_STORAGE;
3073

tests/unit-tests/admin/test-class-sensei-setup-wizard.php

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
class Sensei_Setup_Wizard_Test extends WP_UnitTestCase {
1515
use Sensei_Test_Redirect_Helpers;
1616

17+
/**
18+
* The original screen.
19+
*
20+
* @var WP_Screen
21+
*/
22+
private $original_screen;
23+
1724
/**
1825
* Set up before the class.
1926
*/
@@ -339,7 +346,9 @@ public function testRenderWizardPage_WhenRendered_ClearsRedirectOption() {
339346
update_option( 'sensei_activation_redirect', 1 );
340347

341348
// Act.
349+
ob_start();
342350
Sensei()->setup_wizard->render_wizard_page();
351+
ob_end_clean();
343352

344353
// Assert.
345354
$this->assertFalse( get_option( 'sensei_activation_redirect', false ) );

tests/unit-tests/blocks/test-class-sensei-block-course-progress.php

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class Sensei_Course_Progress_Block_Test extends WP_UnitTestCase {
1414
*/
1515
private $block;
1616

17+
/**
18+
* The course post.
19+
*
20+
* @var WP_Post
21+
*/
22+
private $course;
23+
1724
/**
1825
* Factory for setting up testing data.
1926
*

tests/unit-tests/blocks/test-class-sensei-block-learner-courses.php

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class Sensei_Block_Learner_Courses_Test extends WP_UnitTestCase {
1717
*/
1818
private $block;
1919

20+
/**
21+
* The course post.
22+
*
23+
* @var WP_Post
24+
*/
25+
private $course;
26+
27+
/**
28+
* Factory for setting up testing data.
29+
*
30+
* @var Sensei_Factory
31+
*/
32+
protected $factory;
33+
2034
/**
2135
* Set up the test.
2236
*/

tests/unit-tests/blocks/test-class-sensei-block-view-results.php

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ class Sensei_Block_View_Results_Test extends WP_UnitTestCase {
1717
*/
1818
private $block;
1919

20+
/**
21+
* The course post.
22+
*
23+
* @var WP_Post
24+
*/
25+
private $course;
26+
27+
/**
28+
* Factory for setting up testing data.
29+
*
30+
* @var Sensei_Factory
31+
*/
32+
protected $factory;
33+
2034
/**
2135
* Block content.
2236
*/

0 commit comments

Comments
 (0)