Skip to content

Commit a4720e4

Browse files
committed
ci: add rector
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 8a59655 commit a4720e4

File tree

12 files changed

+425
-379
lines changed

12 files changed

+425
-379
lines changed

.github/workflows/__shared-ci.yml

+13-8
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,45 @@ jobs:
2424
php-version: ${{ matrix.php-versions }}
2525
extensions: none,iconv,dom,curl,mbstring,tokenizer,xml,xmlwriter,simplexml,ctype
2626
coverage: pcov
27-
27+
2828
- name: ♻️ Get composer cache directory
2929
id: composer-cache
3030
shell: bash
3131
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
32-
32+
3333
- name: ♻️ Cache composer dependencies
3434
uses: actions/cache@v4
3535
with:
3636
path: ${{ steps.composer-cache.outputs.dir }}
37-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
37+
key: ${{ runner.os }}-composer-${{ matrix.php-versions }}-${{ hashFiles('**/composer.json') }}
3838
restore-keys: ${{ runner.os }}-composer-
39-
39+
4040
- name: ⚙️ Install dependencies
4141
shell: bash
4242
run: |
4343
composer install --no-progress --prefer-dist --optimize-autoloader
4444
composer --working-dir=tools install --no-progress --prefer-dist --optimize-autoloader
45-
45+
4646
- name: ♻️ Tools cache
4747
uses: actions/cache@v4
4848
with:
4949
path: tools/cache
50-
key: ${{ runner.os }}-tools-${{ github.sha }}
50+
key: ${{ runner.os }}-tools-${{ matrix.php-versions }}-${{ github.sha }}
5151
restore-keys: |
5252
${{ runner.os }}-tools-
5353
5454
- name: 👕 Lint
5555
if: matrix.stable
5656
run: composer php-cs-fixer -- --format=checkstyle | tools/vendor/bin/cs2pr
5757

58+
- name: 🔬 Rector
59+
id: rector
60+
if: matrix.stable
61+
run: composer rector
62+
5863
- name: 🔬 Static analysis
5964
if: matrix.stable
60-
run: composer stan -- --error-format=checkstyle | tools/vendor/bin/cs2pr
65+
run: composer phpstan -- --error-format=github
6166

6267
- name: ♻️ Tests cache
6368
uses: actions/cache@v4
@@ -66,7 +71,7 @@ jobs:
6671
key: ${{ runner.os }}-tests-${{ github.sha }}
6772
restore-keys: |
6873
${{ runner.os }}-tests-
69-
74+
7075
- name: 🧪 Test
7176
run: composer test:ci
7277

Makefile

+9-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ lint: ## Execute lint for given PHP version
3434
@$(call run-php,composer php-cs-fixer $(filter-out $@,$(MAKECMDGOALS)))
3535

3636
lint-fix: ## Execute lint fixing for given PHP version
37-
@$(call run-php,composer php-cs-fixer:fix $(filter-out $@,$(MAKECMDGOALS)))
37+
@$(call run-php,composer php-cs-fixer:fix $(filter-out $@,$(MAKECMDGOALS)))
3838

39-
stan: ## Execute PHPStan for given PHP version
40-
@$(call run-php,composer stan $(filter-out $@,$(MAKECMDGOALS)))
39+
rector: ## Execute rector for given PHP version
40+
@$(call run-php,composer rector $(filter-out $@,$(MAKECMDGOALS)))
41+
42+
rector-fix: ## Execute rector fixing for given PHP version
43+
@$(call run-php,composer rector:fix $(filter-out $@,$(MAKECMDGOALS)))
44+
45+
phpstan: ## Execute PHPStan for given PHP version
46+
@$(call run-php,composer phpstan $(filter-out $@,$(MAKECMDGOALS)))
4147

4248
ci: ## Execute CI scripts for given PHP version
4349
@$(call run-php,composer ci $(filter-out $@,$(MAKECMDGOALS)))

README.md

+1-29
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,4 @@
4444
2. [Usage](https://neilime.github.io/php-css-lint/usage)
4545
3. [Code Coverage](https://codecov.io/gh/neilime/php-css-lint)
4646
4. [PHP Doc](https://neilime.github.io/php-css-lint/phpdoc)
47-
48-
# Development
49-
50-
## Setup
51-
52-
`PHP_VERSION` is the version of php to use during the development. Example: `8.2`
53-
54-
```sh
55-
make build-php PHP_VERSION
56-
make install PHP_VERSION
57-
```
58-
59-
## Running tests
60-
61-
```sh
62-
make test PHP_VERSION
63-
```
64-
65-
## Fix code linting
66-
67-
```sh
68-
make lint-fix PHP_VERSION
69-
```
70-
71-
## Running CI scripts
72-
73-
```sh
74-
make ci PHP_VERSION
75-
```
47+
5. [Development](https://neilime.github.io/php-css-lint/development)

composer.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@
4949
"test:ci": "@test -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/",
5050
"php-cs-fixer": "@php-cs-fixer:fix --dry-run",
5151
"php-cs-fixer:fix": "tools/vendor/bin/php-cs-fixer fix --show-progress=dots --diff --config=.php-cs-fixer.dist.php",
52-
"stan": "tools/vendor/bin/phpstan analyse --level 5 src",
52+
"rector": "@rector:fix --dry-run",
53+
"rector:fix": "tools/vendor/bin/rector process src",
54+
"phpstan": "tools/vendor/bin/phpstan analyse --level max src",
5355
"ci": [
5456
"@php-cs-fixer",
55-
"@stan",
57+
"@rector",
58+
"@phpstan",
5659
"@test:ci"
5760
]
5861
},

rector.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
6+
use Rector\Config\RectorConfig;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
])
13+
->withPhpSets()
14+
->withAttributesSets(
15+
all: true
16+
)
17+
->withPreparedSets(
18+
deadCode: true,
19+
codeQuality: true,
20+
codingStyle: true,
21+
typeDeclarations: true,
22+
privatization: true,
23+
naming: true,
24+
instanceOf: true,
25+
earlyReturn: true,
26+
strictBooleans: true,
27+
carbon: true,
28+
rectorPreset: true,
29+
phpunitCodeQuality: true,
30+
phpunit: true,
31+
)
32+
->withCache(
33+
cacheClass: FileCacheStorage::class,
34+
cacheDirectory: __DIR__ . '/tools/cache/rector'
35+
);;

0 commit comments

Comments
 (0)