Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for certain rules not applying correctly #2

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use Fsylum\RectorWordPress\Rules\FuncCall\ParameterAdderRector;
use Fsylum\RectorWordPress\Rules\FuncCall\ParameterPrependerRector;
use Fsylum\RectorWordPress\ValueObject\FunctionParameterAdder;
use Fsylum\RectorWordPress\ValueObject\FunctionParameterPrepender;
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Removing\ValueObject\RemoveFuncCallArg;

return static function (RectorConfig $rectorConfig): void {
/*
* A bit hackish solution to make sure these specific Rector rules are inserted into the
* sets from the get-go.
*
* Without this, certain rules cannot be applied correctly since Rector is processing files rule by rule.
* For example in WordPressSetList::WP_1_2 we use `RenameFunctionRector` and in WordPressSetList::WP_3_4 we use
* both `ParameterAdderRector` and `RenameFunctionRector` together.
*
* 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(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('_imaginary_function_that_should_not_exists', 0),
]);

$rectorConfig->ruleWithConfiguration(ParameterAdderRector::class, [
new FunctionParameterAdder('_imaginary_function_that_should_not_exists', 0, 'foo'),
]);

$rectorConfig->ruleWithConfiguration(ParameterPrependerRector::class, [
new FunctionParameterPrepender('_imaginary_function_that_should_not_exists', 'foo'),
]);
};
2 changes: 2 additions & 0 deletions config/sets/wp-0.71.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Removing\ValueObject\RemoveFuncCallArg;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('convert_chars', 1),
]);
Expand Down
4 changes: 3 additions & 1 deletion config/sets/wp-1.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {};
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
};
2 changes: 2 additions & 0 deletions config/sets/wp-1.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
'permalink_link' => 'the_permalink',
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-1.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_action', 0, 'retreive_password', 'retrieve_password'),
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'rewrite_rules', 'mod_rewrite_rules'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
'create_user' => 'wp_create_user',
]);
Expand Down
14 changes: 3 additions & 11 deletions config/sets/wp-2.1.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
<?php

use Fsylum\RectorWordPress\Rules\FuncCall\ParameterAdderRector;
use Fsylum\RectorWordPress\Rules\FuncCall\ReturnFirstArgumentRector;
use Fsylum\RectorWordPress\ValueObject\FunctionParameterAdder;
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('get_the_author', 0),
new RemoveFuncCallArg('get_autotoggle', 0),
new RemoveFuncCallArg('wp_get_post_cats', 0),
new RemoveFuncCallArg('wp_set_post_cats', 0),
]);

$rectorConfig->ruleWithConfiguration(ParameterAdderRector::class, [
new FunctionParameterAdder('get_autotoggle', 0, 0),
]);

$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
'links_popup_script',
]);

$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
'get_autotoggle' => '__return_zero',
'get_link' => 'get_bookmark',
'get_settings' => 'get_option',
'wp_get_post_cats' => 'wp_get_post_categories',
'wp_set_post_cats' => 'wp_set_post_categories',
]);

$rectorConfig->ruleWithConfiguration(ReturnFirstArgumentRector::class, [
'get_autotoggle',
]);

/*
* TODO: these are not handled currently
*
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

/*
* TODO: these are not handled currently
*
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('permalink_single_rss', 0),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('trackback_rdf', 0),
new RemoveFuncCallArg('wp_login', 2),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

/*
* TODO: these are not handled currently
*
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('discover_pingback_server_uri', 1),
new RemoveFuncCallArg('wp_get_http_headers', 1),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'tagsperpage', 'edit_tags_per_page'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-2.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

/*
* TODO: these are not handled currently
*
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_settings_field', 3, 'misc', 'general'),
new ReplaceFuncCallArgumentDefaultValue('add_settings_section', 3, 'misc', 'general'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'tag_rewrite_rules', 'post_tag_rewrite_rules'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
'favorite_actions',
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(ParameterAdderRector::class, [
new FunctionParameterAdder('start_post_rel_link', 3, true),
new FunctionParameterAdder('type_url_form_audio', 0, 'audio'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.4.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(ParameterAdderRector::class, [
new FunctionParameterAdder('remove_custom_background', 0, 'custom-background'),
new FunctionParameterAdder('remove_custom_image_header', 0, 'custom-header'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_settings_field', 3, 'privacy', 'reading'),
new ReplaceFuncCallArgumentDefaultValue('add_settings_section', 3, 'privacy', 'reading'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Rector\Transform\ValueObject\MethodCallToFuncCall;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(MethodCallToFuncCallRector::class, [
new MethodCallToFuncCall('wpdb', '_weak_escape', 'esc_sql'),
new MethodCallToFuncCall('wpdb', 'escape', 'esc_sql'),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
'the_attachment_links',
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Rector\Removing\ValueObject\RemoveFuncCallArg;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('wp_notify_postauthor', 1),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-3.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
'_relocate_children',
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('define', 0, 'FORCE_SSL_LOGIN', 'FORCE_SSL_ADMIN'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveMethodCallRector::class, [
'add_tab' => 'WP_Customize_Image_Control',
'prepare_control' => 'WP_Customize_Image_Control',
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Rector\Removing\ValueObject\RemoveFuncCallArg;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('iframe_header', 1),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.3.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'htmledit_pre', 'format_for_editor'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.4.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('get_site_option', 2),
new RemoveFuncCallArg('get_wp_title_rss', 0),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.5.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Rector\Transform\ValueObject\MethodCallToFuncCall;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(MethodCallToFuncCallRector::class, [
new MethodCallToFuncCall('WP_Query', 'is_comments_popup', '__return_false'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.6.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('install_search_form', 0),
new RemoveFuncCallArg('wp_embed_handler_googlevideo', 0),
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'blog_details', 'site_details'),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.8.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Removing\ValueObject\RemoveFuncCallArg;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('get_category_parents', 4),
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-4.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Rector\Renaming\ValueObject\MethodCallRename;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallArgRector::class, [
new RemoveFuncCallArg('term_description', 1),
]);
Expand Down
4 changes: 3 additions & 1 deletion config/sets/wp-5.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {};
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');
};
2 changes: 2 additions & 0 deletions config/sets/wp-5.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [
'upgrade_500',
]);
Expand Down
2 changes: 2 additions & 0 deletions config/sets/wp-5.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../config.php');

$rectorConfig->ruleWithConfiguration(FunctionArgumentDefaultValueReplacerRector::class, [
new ReplaceFuncCallArgumentDefaultValue('add_filter', 0, 'login_headertitle', 'login_headertext'),
]);
Expand Down
Loading
Loading