Skip to content

Commit c2f4802

Browse files
authored
Adding a rector configuration (#426)
1 parent be442bf commit c2f4802

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/.phpcs.xml export-ignore
1010
/.phpcs export-ignore
1111
/phpunit.xml export-ignore
12+
/rector.php export-ignore
1213
/tests export-ignore
1314
/configure.php export-ignore
1415
/Makefile export-ignore

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"require-dev": {
2323
"alleyinteractive/alley-coding-standards": "^2.0",
2424
"mantle-framework/testkit": "^1.4",
25+
"rector/rector": "^2.0",
2526
"szepeviktor/phpstan-wordpress": "^2.0"
2627
},
2728
"config": {
@@ -52,12 +53,16 @@
5253
"phpstan": "phpstan --memory-limit=512M",
5354
"lint": [
5455
"@phpcs",
55-
"@phpstan"
56+
"@phpstan",
57+
"@rector"
5658
],
5759
"lint:fix": [
58-
"@phpcbf"
60+
"@rector:fix",
61+
"@phpcbf"
5962
],
6063
"phpunit": "phpunit",
64+
"rector:fix": "rector process",
65+
"rector": "rector process --dry-run",
6166
"release": "npx @alleyinteractive/create-release@latest",
6267
"test": [
6368
"@phpcs",

rector.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Rector Configuration
4+
*
5+
* @link https://getrector.com/documentation
6+
* @package create-wordpress-plugin
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
use Rector\Config\RectorConfig;
12+
use Rector\PHPUnit\Set\PHPUnitSetList;
13+
14+
return RectorConfig::configure()
15+
->withParallel()
16+
->withIndent(
17+
indentChar: ' ',
18+
indentSize: 1,
19+
)
20+
->withRootFiles()
21+
->withPaths( [
22+
__DIR__ . '/src',
23+
__DIR__ . '/tests',
24+
] )
25+
/**
26+
* --------------------------------------------------------------------------
27+
* Enabled rector rules/rulesets.
28+
* --------------------------------------------------------------------------
29+
*
30+
* @link https://getrector.com/find-rule
31+
*/
32+
->withPreparedSets(
33+
codeQuality: true,
34+
deadCode: true,
35+
earlyReturn: true,
36+
typeDeclarations: true,
37+
)
38+
/**
39+
* --------------------------------------------------------------------------
40+
* Enable Rector to keep your code up-to-date with the latest features from the PHP version in your composer.json file
41+
* --------------------------------------------------------------------------
42+
*/
43+
->withPhpSets()
44+
->withSets( [
45+
PHPUnitSetList::PHPUNIT_100,
46+
PHPUnitSetList::PHPUNIT_110,
47+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
48+
] )
49+
/**
50+
* --------------------------------------------------------------------------
51+
* Rector rules to skip.
52+
* --------------------------------------------------------------------------
53+
*
54+
* @link https://getrector.com/documentation/ignoring-rules-or-paths
55+
*/
56+
->withSkip( [
57+
Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class,
58+
] );

src/assets.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ function validate_path( string $path ): bool {
2424
*
2525
* @param string $dir_entry_name The directory name where the entry point was defined.
2626
* @param boolean $dir Optional. Whether to return the directory path or the plugin URL path. Defaults to false (returns URL).
27-
*
28-
* @return string
2927
*/
3028
function get_entry_dir_path( string $dir_entry_name, bool $dir = false ): string {
3129
// The relative path from the plugin root.
@@ -35,7 +33,7 @@ function get_entry_dir_path( string $dir_entry_name, bool $dir = false ): string
3533

3634
if ( validate_path( $asset_dir_path ) ) {
3735
// Negotiate the base path.
38-
return true === $dir
36+
return $dir
3937
? $asset_dir_path
4038
: plugins_url( $asset_build_dir, __DIR__ );
4139
}
@@ -97,7 +95,7 @@ function get_asset_version( string $dir_entry_name ): string {
9795
* @param string $filename The asset file name including the file type extension to get the public path for.
9896
* @return string The public URL to the asset, empty string otherwise.
9997
*/
100-
function get_entry_asset_url( string $dir_entry_name, $filename = 'index.js' ) {
98+
function get_entry_asset_url( string $dir_entry_name, ?string $filename = 'index.js' ): string {
10199
if ( empty( $filename ) ) {
102100
return '';
103101
}

tests/Feature/ExampleFeatureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ExampleFeatureTest extends TestCase {
1818
/**
1919
* An example test for the example feature. In practice, this should be updated to test an aspect of the feature.
2020
*/
21-
public function test_example() {
21+
public function test_example(): void {
2222
$this->assertTrue( true );
2323
$this->assertNotEmpty( home_url() );
2424
}

tests/Unit/ExampleUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ExampleUnitTest extends TestCase {
1818
/**
1919
* An example unit test. In practice, this should be updated to test a function in isolation.
2020
*/
21-
public function test_that_true_is_true() {
21+
public function test_that_true_is_true(): void {
2222
$this->assertTrue( true );
2323
}
2424
}

0 commit comments

Comments
 (0)