diff --git a/config/config.php b/config/config.php index cf7999f..4a6714a 100644 --- a/config/config.php +++ b/config/config.php @@ -3,12 +3,16 @@ declare(strict_types=1); use Fsylum\RectorWordPress\Rules\FuncCall\ParameterAdderRector; +use Fsylum\RectorWordPress\Rules\MethodCall\ParameterAdderRector as MethodParameterAdderRector; use Fsylum\RectorWordPress\Rules\FuncCall\ParameterPrependerRector; use Fsylum\RectorWordPress\ValueObject\FunctionParameterAdder; use Fsylum\RectorWordPress\ValueObject\FunctionParameterPrepender; +use Fsylum\RectorWordPress\ValueObject\MethodParameterAdder; use Rector\Config\RectorConfig; use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector; use Rector\Removing\ValueObject\RemoveFuncCallArg; +use Rector\Renaming\Rector\MethodCall\RenameMethodRector; +use Rector\Renaming\ValueObject\MethodCallRename; return static function (RectorConfig $rectorConfig): void { /* @@ -22,6 +26,10 @@ * Since `RenameFunctionRector` is parsed earlier, it will rename the all the configured functions and * `ParameterAdderRector` will receive nodes with functions already renamed, so it can never be run successfully. */ + $rectorConfig->ruleWithConfiguration(MethodParameterAdderRector::class, [ + new MethodParameterAdder('_imaginary_class', '_imaginary_method_that_should_not_exists', 0, 'foo'), + ]); + $rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [ new RemoveFuncCallArg('_imaginary_function_that_should_not_exists', 0), ]); @@ -33,4 +41,8 @@ $rectorConfig->ruleWithConfiguration(ParameterPrependerRector::class, [ new FunctionParameterPrepender('_imaginary_function_that_should_not_exists', 'foo'), ]); + + $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ + new MethodCallRename('_imaginary_class', '_old_imaginary_method_that_should_not_exists', '_new_imaginary_method_that_should_not_exists'), + ]); }; diff --git a/config/sets/level/up-to-wp-6.7.php b/config/sets/level/up-to-wp-6.7.php new file mode 100644 index 0000000..ca7e870 --- /dev/null +++ b/config/sets/level/up-to-wp-6.7.php @@ -0,0 +1,9 @@ +sets([WordPressSetList::WP_6_7, WordPressLevelSetList::UP_TO_WP_6_6]); +}; diff --git a/config/sets/level/up-to-wp-6.8.php b/config/sets/level/up-to-wp-6.8.php new file mode 100644 index 0000000..292816b --- /dev/null +++ b/config/sets/level/up-to-wp-6.8.php @@ -0,0 +1,9 @@ +sets([WordPressSetList::WP_6_8, WordPressLevelSetList::UP_TO_WP_6_7]); +}; diff --git a/config/sets/wp-6.7.php b/config/sets/wp-6.7.php new file mode 100644 index 0000000..7a35835 --- /dev/null +++ b/config/sets/wp-6.7.php @@ -0,0 +1,46 @@ +import(__DIR__ . '/../config.php'); + + $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [ + 'wp_get_global_styles_custom_css' => 'wp_get_global_stylesheet', + 'wp_enqueue_global_styles_custom_css' => 'wp_enqueue_global_styles', + 'current_user_can_for_blog' => 'current_user_can_for_site', + ]); + + $rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [ + 'wp_init_targeted_link_rel_filters', + 'wp_remove_targeted_link_rel_filters', + ]); + + $rectorConfig->ruleWithConfiguration(RemoveMethodCallRector::class, [ + 'print_client_interactivity_data' => 'WP_Interactivity_API', + 'register_script_modules' => 'WP_Interactivity_API', + ]); + + $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ + new MethodCallRename('WP_Interactivity_API', 'print_router_loading_and_screen_reader_markup', 'print_router_markup'), + ]); + + /* + * TODO: these are not handled currently + * + * FUNCTIONS + * - wp_simplepie_autoload + * - wp_create_block_style_variation_instance_name + * - wp_targeted_link_rel + * - wp_targeted_link_rel_callback + * + * METHODS + * - WP_Sitemaps::redirect_sitemapxml + * - WP_Theme_JSON::get_custom_css + */ +}; diff --git a/config/sets/wp-6.8.php b/config/sets/wp-6.8.php new file mode 100644 index 0000000..dc55638 --- /dev/null +++ b/config/sets/wp-6.8.php @@ -0,0 +1,24 @@ +import(__DIR__ . '/../config.php'); + + $rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [ + new ReplaceFuncCallArgumentDefaultValue('add_action', 0, 'setted_transient', 'set_transient'), + new ReplaceFuncCallArgumentDefaultValue('add_action', 0, 'setted_site_transient', 'set_site_transient'), + ]); + + /* + * TODO: these are not handled currently + * + * FUNCTIONS + * - wp_add_editor_classic_theme_styles + * + * PROPERTIES + * - WP_HTML_Processor_State::$context_node + */ +}; diff --git a/src/Set/WordPressLevelSetList.php b/src/Set/WordPressLevelSetList.php index e66b7b5..ef5c8bd 100644 --- a/src/Set/WordPressLevelSetList.php +++ b/src/Set/WordPressLevelSetList.php @@ -56,4 +56,6 @@ final class WordPressLevelSetList implements SetListInterface public const UP_TO_WP_6_4 = __DIR__ . '/../../config/sets/level/up-to-wp-6.4.php'; public const UP_TO_WP_6_5 = __DIR__ . '/../../config/sets/level/up-to-wp-6.5.php'; public const UP_TO_WP_6_6 = __DIR__ . '/../../config/sets/level/up-to-wp-6.6.php'; + public const UP_TO_WP_6_7 = __DIR__ . '/../../config/sets/level/up-to-wp-6.7.php'; + public const UP_TO_WP_6_8 = __DIR__ . '/../../config/sets/level/up-to-wp-6.8.php'; } diff --git a/src/Set/WordPressSetList.php b/src/Set/WordPressSetList.php index 3505e5c..3edb76f 100644 --- a/src/Set/WordPressSetList.php +++ b/src/Set/WordPressSetList.php @@ -56,4 +56,6 @@ final class WordPressSetList implements SetListInterface public const WP_6_4 = __DIR__ . '/../../config/sets/wp-6.4.php'; public const WP_6_5 = __DIR__ . '/../../config/sets/wp-6.5.php'; public const WP_6_6 = __DIR__ . '/../../config/sets/wp-6.6.php'; + public const WP_6_7 = __DIR__ . '/../../config/sets/wp-6.7.php'; + public const WP_6_8 = __DIR__ . '/../../config/sets/wp-6.8.php'; } diff --git a/tests/Rector/Sets/Level/UpToWp66/UpToWp66Test.php b/tests/Rector/Sets/Level/UpToWp68/UpToWp68Test.php similarity index 88% rename from tests/Rector/Sets/Level/UpToWp66/UpToWp66Test.php rename to tests/Rector/Sets/Level/UpToWp68/UpToWp68Test.php index 7245df5..20fd16c 100644 --- a/tests/Rector/Sets/Level/UpToWp66/UpToWp66Test.php +++ b/tests/Rector/Sets/Level/UpToWp68/UpToWp68Test.php @@ -1,6 +1,6 @@ create_attachment_object('foo', 1); $foo = wp_interactivity_process_directives_of_interactive_blocks($bar); $foo = wp_render_elements_support($bar); +// 6.7 +wp_get_global_styles_custom_css(); +wp_enqueue_global_styles_custom_css(); + +if (current_user_can_for_blog(1, 'edit_posts')) { + echo 'foo'; +} + +wp_init_targeted_link_rel_filters(); +wp_remove_targeted_link_rel_filters(); + +(new WP_Interactivity_API)->print_client_interactivity_data(); +(new WP_Interactivity_API)->register_script_modules(); + +(new WP_Interactivity_API)->print_router_loading_and_screen_reader_markup(); + +// 6.8 +add_action( 'setted_transient', 'foo', 'bar', 10 ); +add_action( 'setted_site_transient', 'foo', 'bar', 10 ); + ?> ----- print_router_markup(); + +// 6.8 +add_action( 'set_transient', 'foo', 'bar', 10 ); +add_action( 'set_site_transient', 'foo', 'bar', 10 ); + ?> diff --git a/tests/Rector/Sets/Wp67/Wp67Test.php b/tests/Rector/Sets/Wp67/Wp67Test.php new file mode 100644 index 0000000..2b00a0d --- /dev/null +++ b/tests/Rector/Sets/Wp67/Wp67Test.php @@ -0,0 +1,29 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/../../../../config/sets/wp-6.7.php'; + } +} diff --git a/tests/Rector/Sets/Wp67/test_fixture.php.inc b/tests/Rector/Sets/Wp67/test_fixture.php.inc new file mode 100644 index 0000000..a701ee5 --- /dev/null +++ b/tests/Rector/Sets/Wp67/test_fixture.php.inc @@ -0,0 +1,31 @@ +print_client_interactivity_data(); +(new WP_Interactivity_API)->register_script_modules(); + +(new WP_Interactivity_API)->print_router_loading_and_screen_reader_markup(); + +?> +----- +print_router_markup(); + +?> diff --git a/tests/Rector/Sets/Wp68/Wp68Test.php b/tests/Rector/Sets/Wp68/Wp68Test.php new file mode 100644 index 0000000..1fa4ed3 --- /dev/null +++ b/tests/Rector/Sets/Wp68/Wp68Test.php @@ -0,0 +1,29 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/../../../../config/sets/wp-6.8.php'; + } +} diff --git a/tests/Rector/Sets/Wp68/test_fixture.php.inc b/tests/Rector/Sets/Wp68/test_fixture.php.inc new file mode 100644 index 0000000..87e8a24 --- /dev/null +++ b/tests/Rector/Sets/Wp68/test_fixture.php.inc @@ -0,0 +1,13 @@ + +----- +