From aeba9d183d1b13616ac62e86e7ba310723ee6320 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 11 Sep 2023 04:51:09 +0000 Subject: [PATCH] Code Modernization: Use `dirname()` with the `$levels` parameter. PHP 7.0 introduced the `$levels` parameter to the `dirname()` function, which means nested calls to `dirname()` are no longer needed. Note: This is enforced by WPCS 3.0.0. Reference: [https://www.php.net/manual/en/function.dirname.php PHP Manual: dirname()]. Follow-up to [56141]. Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56552 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/theme.php | 2 +- src/wp-admin/maint/repair.php | 2 +- tests/phpunit/includes/bootstrap.php | 4 ++-- tests/phpunit/tests/filesystem/base.php | 2 +- tests/phpunit/tests/pomo/pluralForms.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index d98cb5de33..b0b3c6d768 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -156,7 +156,7 @@ function get_page_templates( $post = null, $post_type = 'page' ) { * @return string */ function _get_template_edit_filename( $fullpath, $containingfolder ) { - return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath ); + return str_replace( dirname( $containingfolder, 2 ), '', $fullpath ); } /** diff --git a/src/wp-admin/maint/repair.php b/src/wp-admin/maint/repair.php index 554e466d76..1c0f6ffa98 100644 --- a/src/wp-admin/maint/repair.php +++ b/src/wp-admin/maint/repair.php @@ -7,7 +7,7 @@ */ define( 'WP_REPAIRING', true ); -require_once dirname( dirname( __DIR__ ) ) . '/wp-load.php'; +require_once dirname( __DIR__, 2 ) . '/wp-load.php'; header( 'Content-Type: text/html; charset=utf-8' ); ?> diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 43ba0b0c49..15ec06b081 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -10,7 +10,7 @@ if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) ) { if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { // Support the config file from the root of the develop repository. if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) { - $config_file_path = dirname( dirname( $config_file_path ) ); + $config_file_path = dirname( $config_file_path, 2 ); } } $config_file_path .= '/wp-tests-config.php'; @@ -79,7 +79,7 @@ if ( version_compare( $phpunit_version, '5.7.21', '<' ) ) { */ if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) { // Default location of the autoloader for WP core test runs. - $phpunit_polyfills_autoloader = dirname( dirname( dirname( __DIR__ ) ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; + $phpunit_polyfills_autoloader = dirname( __DIR__, 3 ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; $phpunit_polyfills_error = false; // Allow for a custom installation location to be provided for plugin/theme integration tests. diff --git a/tests/phpunit/tests/filesystem/base.php b/tests/phpunit/tests/filesystem/base.php index 52ab59e3cd..ceefeafa3e 100644 --- a/tests/phpunit/tests/filesystem/base.php +++ b/tests/phpunit/tests/filesystem/base.php @@ -24,7 +24,7 @@ abstract class WP_Filesystem_UnitTestCase extends WP_UnitTestCase { return 'MockFS'; } public function filter_abstraction_file( $file ) { - return dirname( dirname( __DIR__ ) ) . '/includes/mock-fs.php'; + return dirname( __DIR__, 2 ) . '/includes/mock-fs.php'; } public function test_is_MockFS_sane() { diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 439064f7c4..b676735c59 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -43,7 +43,7 @@ class PluralFormsTest extends WP_UnitTestCase { * @group external-http */ public function test_regression( $lang, $nplurals, $expression ) { - require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; + require_once dirname( __DIR__, 2 ) . '/includes/plural-form-function.php'; $parenthesized = self::parenthesize_plural_expression( $expression ); $old_style = tests_make_plural_form_function( $nplurals, $parenthesized );