Skip to content

Commit

Permalink
Merge pull request #6 from fsylum/feature-wp65
Browse files Browse the repository at this point in the history
Add support for WordPress 6.5
  • Loading branch information
fsylum authored Apr 29, 2024
2 parents c46215f + 96250e6 commit c31ce6b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 3 deletions.
9 changes: 9 additions & 0 deletions config/sets/level/up-to-wp-6.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Fsylum\RectorWordPress\Set\WordPressLevelSetList;
use Fsylum\RectorWordPress\Set\WordPressSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([WordPressSetList::WP_6_5, WordPressLevelSetList::UP_TO_WP_6_4]);
};
33 changes: 33 additions & 0 deletions config/sets/wp-6.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Fsylum\RectorWordPress\Rules\MethodCall\ParameterAdderRector;
use Fsylum\RectorWordPress\ValueObject\MethodParameterAdder;
use Rector\Config\RectorConfig;
use Rector\Transform\Rector\MethodCall\MethodCallToFuncCallRector;
use Rector\Transform\ValueObject\MethodCallToFuncCall;

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

$rectorConfig->ruleWithConfiguration(ParameterAdderRector::class, [
new MethodParameterAdder('Custom_Image_Header', 'create_attachment_object', 2, 'custom-header'),
new MethodParameterAdder('WP_Site_Icon', 'create_attachment_object', 2, 'site-icon'),
]);

$rectorConfig->ruleWithConfiguration(MethodCallToFuncCallRector::class, [
new MethodCallToFuncCall('Custom_Image_Header', 'create_attachment_object', 'wp_copy_parent_attachment_properties'),
new MethodCallToFuncCall('WP_Site_Icon', 'create_attachment_object', 'wp_copy_parent_attachment_properties'),
]);

/*
* TODO: these are not handled currently
*
* FUNCTIONS
* - block_core_query_ensure_interactivity_dependency
* - block_core_file_ensure_interactivity_dependency
* - block_core_image_ensure_interactivity_dependency
*
* METHODS
* - Translations::parenthesize_plural_exression
*/
};
2 changes: 2 additions & 0 deletions src/Set/WordPressLevelSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ final class WordPressLevelSetList implements SetListInterface
public const UP_TO_WP_6_3 = __DIR__ . '/../../config/sets/level/up-to-wp-6.3.php';

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';
}
2 changes: 2 additions & 0 deletions src/Set/WordPressSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@ final class WordPressSetList implements SetListInterface
public const WP_6_3 = __DIR__ . '/../../config/sets/wp-6.3.php';

public const WP_6_4 = __DIR__ . '/../../config/sets/wp-6.4.php';

public const WP_6_5 = __DIR__ . '/../../config/sets/wp-6.5.php';
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Fsylum\RectorWordPress\Tests\Rector\Sets\Level\UpToWp64;
namespace Fsylum\RectorWordPress\Tests\Rector\Sets\Level\UpToWp65;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
Expand All @@ -9,7 +9,7 @@
/**
* @internal
*/
final class UpToWp64Test extends AbstractRectorTestCase
final class UpToWp65Test extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
Expand All @@ -24,6 +24,6 @@ public static function provideData(): Iterator

public function provideConfigFilePath(): string
{
return __DIR__ . '/../../../../../config/sets/level/up-to-wp-6.4.php';
return __DIR__ . '/../../../../../config/sets/level/up-to-wp-6.5.php';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ wp_img_tag_add_decoding_attr('foo', 'bar');
$foo = TEMPLATEPATH;
$bar = STYLESHEETPATH;

// 6.5
$class1 = new Custom_Image_Header;
$class2 = new WP_Site_Icon;

$class1->create_attachment_object('foo', 1);
$class2->create_attachment_object('foo', 1);

?>
-----
<?php
Expand Down Expand Up @@ -676,4 +683,11 @@ wp_img_tag_add_loading_optimization_attrs('foo', 'bar');
$foo = \get_template_directory();
$bar = \get_stylesheet_directory();

// 6.5
$class1 = new Custom_Image_Header;
$class2 = new WP_Site_Icon;

\wp_copy_parent_attachment_properties('foo', 1, 'custom-header');
\wp_copy_parent_attachment_properties('foo', 1, 'site-icon');

?>
29 changes: 29 additions & 0 deletions tests/Rector/Sets/Wp65/Wp65Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Fsylum\RectorWordPress\Tests\Rector\Sets\Wp65;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

/**
* @internal
*/
final class Wp65Test extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__);
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/../../../../config/sets/wp-6.5.php';
}
}
19 changes: 19 additions & 0 deletions tests/Rector/Sets/Wp65/test_fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$class1 = new Custom_Image_Header;
$class2 = new WP_Site_Icon;

$class1->create_attachment_object('foo', 1);
$class2->create_attachment_object('foo', 1);

?>
-----
<?php

$class1 = new Custom_Image_Header;
$class2 = new WP_Site_Icon;

\wp_copy_parent_attachment_properties('foo', 1, 'custom-header');
\wp_copy_parent_attachment_properties('foo', 1, 'site-icon');

?>

0 comments on commit c31ce6b

Please sign in to comment.