Code Modernization: Remove all code using a version_compare() with a PHP version older than PHP 5.6.

Props jrf.
Fixes #48074.

git-svn-id: https://develop.svn.wordpress.org/trunk@46214 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-09-20 22:01:36 +00:00
parent 92d70ed696
commit 099adc0243
16 changed files with 9 additions and 104 deletions

View File

@ -8,16 +8,6 @@
<!-- Default test suite to run all tests -->
<testsuite name="default">
<directory suffix=".php">tests/phpunit/tests</directory>
<file phpVersion="5.3.0">tests/phpunit/tests/actions/closures.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editor.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorGd.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorImagick.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/oembed/headers.php</file>
<exclude>tests/phpunit/tests/actions/closures.php</exclude>
<exclude>tests/phpunit/tests/image/editor.php</exclude>
<exclude>tests/phpunit/tests/image/editorGd.php</exclude>
<exclude>tests/phpunit/tests/image/editorImagick.php</exclude>
<exclude>tests/phpunit/tests/oembed/headers.php</exclude>
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
</testsuite>
<!-- Sets the DOING_AUTOSAVE constant, so needs to be run last -->

View File

@ -1376,13 +1376,6 @@ final class WP_Customize_Manager {
)
);
// In PHP < 5.6 filesize() returns 0 for the temp files unless we clear the file status cache.
// Technically, PHP < 5.6.0 || < 5.5.13 || < 5.4.29 but no need to be so targeted.
// See https://bugs.php.net/bug.php?id=65701
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
clearstatcache();
}
$attachment_id = media_handle_sideload( $file_array, 0, null, $attachment_post_data );
if ( is_wp_error( $attachment_id ) ) {
continue;

View File

@ -199,13 +199,8 @@ class WP_Locale {
/* translators: $thousands_sep argument for https://secure.php.net/number_format, default is ',' */
$thousands_sep = __( 'number_format_thousands_sep' );
if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) {
// Replace space with a non-breaking space to avoid wrapping.
$thousands_sep = str_replace( ' ', '&nbsp;', $thousands_sep );
} else {
// PHP < 5.4.0 does not support multiple bytes in thousands separator.
$thousands_sep = str_replace( array( '&nbsp;', '&#160;' ), ' ', $thousands_sep );
}
// Replace space with a non-breaking space to avoid wrapping.
$thousands_sep = str_replace( ' ', '&nbsp;', $thousands_sep );
$this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep;

View File

@ -5572,15 +5572,10 @@ function _print_emoji_detection_script() {
* @return string The encoded content.
*/
function wp_encode_emoji( $content ) {
$emoji = _wp_emoji_list( 'partials' );
$compat = version_compare( phpversion(), '5.4', '<' );
$emoji = _wp_emoji_list( 'partials' );
foreach ( $emoji as $emojum ) {
if ( $compat ) {
$emoji_char = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
} else {
$emoji_char = html_entity_decode( $emojum );
}
$emoji_char = html_entity_decode( $emojum );
if ( false !== strpos( $content, $emoji_char ) ) {
$content = preg_replace( "/$emoji_char/", $emojum, $content );
}
@ -5616,14 +5611,9 @@ function wp_staticize_emoji( $text ) {
// Quickly narrow down the list of emoji that might be in the text and need replacing.
$possible_emoji = array();
$compat = version_compare( phpversion(), '5.4', '<' );
foreach ( $emoji as $emojum ) {
if ( false !== strpos( $text, $emojum ) ) {
if ( $compat ) {
$possible_emoji[ $emojum ] = html_entity_decode( $emojum, ENT_COMPAT, 'UTF-8' );
} else {
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
}
$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
}
}

View File

@ -6004,12 +6004,7 @@ function wp_allowed_protocols() {
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) {
static $truncate_paths;
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) {
$trace = debug_backtrace( false );
} else {
$trace = debug_backtrace();
}
$trace = debug_backtrace( false );
$caller = array();
$check_class = ! is_null( $ignore_class );
$skip_frames++; // skip this function

View File

@ -465,12 +465,8 @@ class WpdbExposedMethodsForTesting extends wpdb {
function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
$saved_config = ini_get( 'pcre.backtrack_limit' );
// Attempt to prevent PHP crashes. Adjust these lower when needed.
if ( version_compare( phpversion(), '5.4.8', '>' ) ) {
$limit = 1000000;
} else {
$limit = 20000; // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10
}
// Attempt to prevent PHP crashes. Adjust these lower when needed.
$limit = 1000000;
// Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem.
for ( $i = 4; $i <= $limit; $i *= 2 ) {

View File

@ -12,14 +12,6 @@
<!-- Default test suite to run all tests -->
<testsuite name="default">
<directory suffix=".php">tests</directory>
<file phpVersion="5.3.0">tests/phpunit/tests/actions/closures.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editor.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorGd.php</file>
<file phpVersion="5.3.0">tests/phpunit/tests/image/editorImagick.php</file>
<exclude>tests/phpunit/tests/actions/closures.php</exclude>
<exclude>tests/phpunit/tests/image/editor.php</exclude>
<exclude>tests/phpunit/tests/image/editorGd.php</exclude>
<exclude>tests/phpunit/tests/image/editorImagick.php</exclude>
<!-- Path relative to the checkout root, for PHPUnit 3.6.x -->
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
<!-- Same path relative to the configuration file, for PHPUnit 4.0.0+ -->

View File

@ -24,10 +24,6 @@ class Tests_Admin_WpPrivacyRequestsTable extends WP_UnitTestCase {
* @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table $instance Mocked class instance.
*/
public function get_mocked_class_instance() {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
}
$args = array(
'plural' => 'privacy_requests',
'singular' => 'privacy_request',

View File

@ -249,11 +249,6 @@ EOT;
$this->markTestSkipped( 'The intl extension is not loaded. ResourceBundle not tested for is_countable().' );
}
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
$this->markTestSkipped( 'ResourceBundle is only countable in PHP 5.4+' );
return;
}
$this->assertTrue( is_countable( new ResourceBundle( 'en', null ) ) );
}

View File

@ -1083,9 +1083,7 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
);
// Add global namespace prefix to check #41488.
if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
$original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
}
$original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
$args = $menus->filter_wp_nav_menu_args( $original_args );

View File

@ -482,10 +482,6 @@ class Tests_DB_Charset extends WP_UnitTestCase {
* @ticket 21212
*/
function test_strip_invalid_text( $data, $expected, $message ) {
if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) {
$this->markTestSkipped( 'This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262' );
}
$charset = self::$_wpdb->charset;
if ( isset( $data[0]['connection_charset'] ) ) {
$new_charset = $data[0]['connection_charset'];

View File

@ -918,10 +918,6 @@ class Tests_Functions extends WP_UnitTestCase {
* @ticket 28786
*/
function test_wp_json_encode_depth() {
if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
$this->markTestSkipped( 'json_encode() supports the $depth parameter in PHP 5.5+' );
};
$data = array( array( array( 1, 2, 3 ) ) );
$json = wp_json_encode( $data, 0, 1 );
$this->assertFalse( $json );

View File

@ -705,11 +705,6 @@ class Tests_Post_Query extends WP_UnitTestCase {
* @dataProvider set_found_posts_provider
*/
public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
return;
}
$q = new WP_Query(
array(
'post_type' => 'wptests_pt',

View File

@ -491,10 +491,6 @@ class Tests_REST_Request extends WP_UnitTestCase {
}
public function test_has_valid_params_json_error() {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
}
$this->request->set_header( 'Content-Type', 'application/json' );
$this->request->set_body( '{"invalid": JSON}' );
@ -507,10 +503,6 @@ class Tests_REST_Request extends WP_UnitTestCase {
public function test_has_valid_params_empty_json_no_error() {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
}
$this->request->set_header( 'Content-Type', 'application/json' );
$this->request->set_body( '' );

View File

@ -126,10 +126,6 @@ class Tests_Theme_Custom_Header extends WP_UnitTestCase {
$this->assertFalse( has_custom_header() );
$this->assertEmpty( $html );
// ReflectionMethod::setAccessible is only available in PHP 5.3+
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
return;
}
// The container should always be returned in the Customizer preview.
$this->_set_customize_previewing( true );
$html = get_custom_header_markup();
@ -226,11 +222,6 @@ class Tests_Theme_Custom_Header extends WP_UnitTestCase {
}
function test_header_script_is_enqueued_by_the_custom_header_markup_without_video_when_previewing_in_customizer() {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
return;
}
$this->_add_theme_support(
array(
'video' => true,

View File

@ -479,11 +479,6 @@ class Test_WP_Widget_Media extends WP_UnitTestCase {
* @covers WP_Widget_Media::has_content()
*/
function test_has_content() {
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
$this->markTestSkipped( 'ReflectionMethod::setAccessible is only available for PHP 5.3+' );
return;
}
$attachment_id = self::factory()->attachment->create_object(
array(
'file' => DIR_TESTDATA . '/images/canola.jpg',