Skip to content

Commit c7b3cba

Browse files
committed
Add Rector to project
1 parent 5c645c4 commit c7b3cba

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- php-version: 8.2
1919
phing_tasks: "phpunitfast"
2020
- php-version: 8.3
21-
phing_tasks: "phpunitfast phpcs-console php-cs-fixer-dryrun phpstan-console"
21+
phing_tasks: "phpunitfast phpcs-console php-cs-fixer-dryrun phpstan-console rector-console"
2222

2323
steps:
2424
- name: Setup PHP
@@ -27,6 +27,13 @@ jobs:
2727
php-version: ${{ matrix.php-version }}
2828
extensions: intl, xsl
2929

30+
- name: Cache rector data
31+
uses: actions/cache@v4
32+
with:
33+
path: .rector
34+
key: "php-${{ matrix.php-version }}-rector-${{ github.sha }}"
35+
restore-keys: "php-${{ matrix.php-version }}-rector-"
36+
3037
- name: Checkout
3138
uses: actions/checkout@v4
3239

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ composer.lock
33
.php_cs_cache
44
.phpstan_cache
55
tests/.phpunit.result.cache
6+
.rector

build.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<phingcall target="phpmd"/>
3939
<phingcall target="pdepend"/>
4040
<phingcall target="phpstan-checkstyle"/>
41+
<phingcall target="rector-console"/>
4142
</target>
4243

4344
<!-- Report rule violations with PHPMD (mess detector) -->
@@ -82,6 +83,18 @@
8283
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G analyse" />
8384
</exec>
8485
</target>
86+
87+
<!-- Rector -->
88+
<target name="rector-console">
89+
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
90+
<arg line="--config=${srcdir}/tests/rector.php --dry-run" />
91+
</exec>
92+
</target>
93+
<target name="rector">
94+
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
95+
<arg line="--config=${srcdir}/tests/rector.php" />
96+
</exec>
97+
</target>
8598

8699
<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
87100
<target name="php-cs-fixer">

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"phpstan/phpstan": "1.12.7",
3434
"phpunit/phpunit": "10.5.36",
3535
"phing/phing": "3.0",
36+
"rector/rector": "^1.2",
3637
"squizlabs/php_codesniffer": "3.10.3"
3738
}
3839
}

tests/phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<file>.</file>
66
<exclude-pattern>*/config/*</exclude-pattern>
77
<exclude-pattern>*.php-cs-fixer.*</exclude-pattern>
8+
<exclude-pattern>*rector.*</exclude-pattern>
89
<arg name="extensions" value="php"/>
910
<!-- We only use PEAR to ensure complete comments at this time -->
1011
<rule ref="PEAR.Commenting">

tests/rector.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
6+
use Rector\Config\RectorConfig;
7+
use Rector\PHPUnit\Set\PHPUnitSetList;
8+
9+
return RectorConfig::configure()
10+
->withCache(
11+
cacheClass: FileCacheStorage::class,
12+
cacheDirectory: __DIR__ . '/../.rector'
13+
)->withPaths([
14+
__DIR__ . '/../src',
15+
])
16+
->withSets([
17+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
18+
])
19+
->withTypeCoverageLevel(0)
20+
->withDeadCodeLevel(6)
21+
->withCodeQualityLevel(18);

0 commit comments

Comments
 (0)