From 9e4188b93b3c1967ecb685c5ead3657583d7e2e2 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 3 Aug 2023 19:50:20 +0000 Subject: [PATCH] Code Modernization: Use "declare" in WP_List_Table magic methods deprecation message Changes "define" to "declare" in the deprecation message in `WP_List_Table` magic methods. Why is "declare" better? It aligns well to: * the topic of and published information about dynamic properties. * the act of explicitly listing the variable as a property on the class. The goal of this message is guide developers to change their code. Changing the term to "declare" hopefully will aid in the understanding of what is being asked of developers when this deprecation is thrown. Follow-up [56349]. Props hellofromTonya, antonvlasenko. Fixes #58896. git-svn-id: https://develop.svn.wordpress.org/trunk@56356 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-list-table.php | 16 +++++------ tests/phpunit/tests/admin/wpListTable.php | 28 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index c7c38a3561..03fe097538 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -187,8 +187,8 @@ class WP_List_Table { } trigger_error( - "The property `{$name}` is not defined. Getting a dynamic (undefined) property is " . - 'deprecated since version 6.4.0! Instead, define the property on the class.', + "The property `{$name}` is not declared. Getting a dynamic property is " . + 'deprecated since version 6.4.0! Instead, declare the property on the class.', E_USER_DEPRECATED ); return null; @@ -210,8 +210,8 @@ class WP_List_Table { } trigger_error( - "The property `{$name}` is not defined. Setting a dynamic (undefined) property is " . - 'deprecated since version 6.4.0! Instead, define the property on the class.', + "The property `{$name}` is not declared. Setting a dynamic property is " . + 'deprecated since version 6.4.0! Instead, declare the property on the class.', E_USER_DEPRECATED ); } @@ -231,8 +231,8 @@ class WP_List_Table { } trigger_error( - "The property `{$name}` is not defined. Checking `isset()` on a dynamic (undefined) property " . - 'is deprecated since version 6.4.0! Instead, define the property on the class.', + "The property `{$name}` is not declared. Checking `isset()` on a dynamic property " . + 'is deprecated since version 6.4.0! Instead, declare the property on the class.', E_USER_DEPRECATED ); return false; @@ -253,8 +253,8 @@ class WP_List_Table { } trigger_error( - "A property `{$name}` is not defined. Unsetting a dynamic (undefined) property is " . - 'deprecated since version 6.4.0! Instead, define the property on the class.', + "A property `{$name}` is not declared. Unsetting a dynamic property is " . + 'deprecated since version 6.4.0! Instead, declare the property on the class.', E_USER_DEPRECATED ); } diff --git a/tests/phpunit/tests/admin/wpListTable.php b/tests/phpunit/tests/admin/wpListTable.php index 3b24cc5d90..4a220bb083 100644 --- a/tests/phpunit/tests/admin/wpListTable.php +++ b/tests/phpunit/tests/admin/wpListTable.php @@ -371,7 +371,7 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { * @param string $property_name Property name to get. * @param mixed $expected Expected value. */ - public function test_should_get_compat_fields_defined_property( $property_name, $expected ) { + public function test_should_get_compat_fields( $property_name, $expected ) { $list_table = new WP_List_Table( array( 'plural' => '_wp_tests__get' ) ); if ( 'screen' === $property_name ) { @@ -389,10 +389,10 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { public function test_should_throw_deprecation_when_getting_dynamic_property() { $this->expectDeprecation(); $this->expectDeprecationMessage( - 'The property `undefined_property` is not defined. Getting a dynamic (undefined) property is ' . - 'deprecated since version 6.4.0! Instead, define the property on the class.' + 'The property `undeclared_property` is not declared. Getting a dynamic property is ' . + 'deprecated since version 6.4.0! Instead, declare the property on the class.' ); - $this->assertNull( $this->list_table->undefined_property, 'Getting a dynamic property should return null from WP_List_Table::__get()' ); + $this->assertNull( $this->list_table->undeclared_property, 'Getting a dynamic property should return null from WP_List_Table::__get()' ); } /** @@ -418,10 +418,10 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { public function test_should_throw_deprecation_when_setting_dynamic_property() { $this->expectDeprecation(); $this->expectDeprecationMessage( - 'The property `undefined_property` is not defined. Setting a dynamic (undefined) property is ' . - 'deprecated since version 6.4.0! Instead, define the property on the class.' + 'The property `undeclared_property` is not declared. Setting a dynamic property is ' . + 'deprecated since version 6.4.0! Instead, declare the property on the class.' ); - $this->list_table->undefined_property = 'some value'; + $this->list_table->undeclared_property = 'some value'; } /** @@ -433,7 +433,7 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { * @param string $property_name Property name to check. * @param mixed $expected Expected value. */ - public function test_should_isset_compat_fields_defined_property( $property_name, $expected ) { + public function test_should_isset_compat_fields( $property_name, $expected ) { $actual = isset( $this->list_table->$property_name ); if ( is_null( $expected ) ) { $this->assertFalse( $actual ); @@ -450,10 +450,10 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { public function test_should_throw_deprecation_when_isset_of_dynamic_property() { $this->expectDeprecation(); $this->expectDeprecationMessage( - 'The property `undefined_property` is not defined. Checking `isset()` on a dynamic (undefined) property ' . - 'is deprecated since version 6.4.0! Instead, define the property on the class.' + 'The property `undeclared_property` is not declared. Checking `isset()` on a dynamic property ' . + 'is deprecated since version 6.4.0! Instead, declare the property on the class.' ); - $this->assertFalse( isset( $this->list_table->undefined_property ), 'Checking a dyanmic property should return false from WP_List_Table::__isset()' ); + $this->assertFalse( isset( $this->list_table->undeclared_property ), 'Checking a dynamic property should return false from WP_List_Table::__isset()' ); } /** @@ -477,10 +477,10 @@ class Tests_Admin_WpListTable extends WP_UnitTestCase { public function test_should_throw_deprecation_when_unset_of_dynamic_property() { $this->expectDeprecation(); $this->expectDeprecationMessage( - 'A property `undefined_property` is not defined. Unsetting a dynamic (undefined) property is ' . - 'deprecated since version 6.4.0! Instead, define the property on the class.' + 'A property `undeclared_property` is not declared. Unsetting a dynamic property is ' . + 'deprecated since version 6.4.0! Instead, declare the property on the class.' ); - unset( $this->list_table->undefined_property ); + unset( $this->list_table->undeclared_property ); } /**