Skip to content

Commit b6e2de6

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

File tree

8 files changed

+155
-112
lines changed

8 files changed

+155
-112
lines changed

.github/workflows/__shared-ci.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ 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 }}
3737
key: ${{ runner.os }}-composer-${{ 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:
@@ -55,9 +55,25 @@ jobs:
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: |
62+
REPORT=$(composer rector -- --output-format json || true)
63+
echo "report<<EOF" >> "$GITHUB_OUTPUT" && echo "$REPORT" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT"
64+
65+
- uses: actions/github-script@v6
66+
if: matrix.stable
67+
with:
68+
script: |
69+
console.log(`::group::Rector report`);
70+
console.log(`::error file=src/CssLint/CliArgs.php,line=41::StrStartsWithRector / NullToStrictStringFuncCallArgRector%0A%0A--- Original%0A+++ New%0A@@ -42,13 +42,13 @@%0A %0A foreach ($aArguments as $sArgument) {%0A // --foo --bar=baz%0A- if (substr($sArgument, 0, 2) == '--') {%0A- $sEqualPosition = strpos($sArgument, '=');%0A+ if (str_starts_with((string) $sArgument, '--')) {%0A+ $sEqualPosition = strpos((string) $sArgument, '=');%0A %0A // --bar=baz%0A if ($sEqualPosition !== false) {%0A- $sKey = substr($sArgument, 2, $sEqualPosition - 2);%0A- $sValue = substr($sArgument, $sEqualPosition + 1);%0A+ $sKey = substr((string) $sArgument, 2, $sEqualPosition - 2);%0A+ $sValue = substr((string) $sArgument, $sEqualPosition + 1);%0A $aParsedArguments[$sKey] = $sValue;%0A }%0A }%0A`);
71+
console.log(`::error file=src/CssLint/Linter.php,line=388::StrStartsWithRector%0A%0A--- Original%0A+++ New%0A@@ -389,7 +389,7 @@%0A $sPropertyName = trim($this->getContextContent());%0A %0A // Ignore CSS variables (names starting with --)%0A- if (substr($sPropertyName, 0, 2) === '--') {%0A+ if (str_starts_with($sPropertyName, '--')) {%0A $this->setContext(self::CONTEXT_PROPERTY_CONTENT);%0A return true;%0A }%0A`);
72+
console.log(`::endgroup::`);
73+
5874
- name: 🔬 Static analysis
5975
if: matrix.stable
60-
run: composer stan -- --error-format=checkstyle | tools/vendor/bin/cs2pr
76+
run: composer stan -- --error-format=github
6177

6278
- name: ♻️ Tests cache
6379
uses: actions/cache@v4
@@ -66,7 +82,7 @@ jobs:
6682
key: ${{ runner.os }}-tests-${{ github.sha }}
6783
restore-keys: |
6884
${{ runner.os }}-tests-
69-
85+
7086
- name: 🧪 Test
7187
run: composer test:ci
7288

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ 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)))
38+
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)))
3844

3945
stan: ## Execute PHPStan for given PHP version
4046
@$(call run-php,composer stan $(filter-out $@,$(MAKECMDGOALS)))

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
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+
"stan": "tools/vendor/bin/phpstan analyse --level max src",
5355
"ci": [
5456
"@php-cs-fixer",
57+
"@rector",
5558
"@stan",
5659
"@test:ci"
5760
]

rector.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
->withCache(
15+
cacheClass: FileCacheStorage::class,
16+
cacheDirectory: __DIR__ . '/tools/cache/rector'
17+
);;

src/CssLint/CliArgs.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ class CliArgs
99

1010
/**
1111
* Constructor
12-
* @param array $aArguments arguments to be parsed (@see $_SERVER['argv'])
12+
* @param array $arguments arguments to be parsed (@see $_SERVER['argv'])
1313
* Accepts "-o", "--options" '{}'
1414
* Accepts a string as last argument, a file path or a string containing CSS
1515
*/
16-
public function __construct(array $aArguments)
16+
public function __construct(array $arguments)
1717
{
18-
if (empty($aArguments) || count($aArguments) === 1) {
18+
if (empty($arguments) || count($arguments) === 1) {
1919
return;
2020
}
2121

22-
array_shift($aArguments);
22+
array_shift($arguments);
2323

24-
$this->filePathOrCssString = array_pop($aArguments);
24+
$this->filePathOrCssString = array_pop($arguments);
2525

26-
if ($aArguments) {
27-
$aParsedArguments = $this->extractArguments($aArguments);
26+
if ($arguments) {
27+
$aParsedArguments = $this->extractArguments($arguments);
2828

2929
if (!empty($aParsedArguments['options'])) {
3030
$this->options = $aParsedArguments['options'];
@@ -33,14 +33,14 @@ public function __construct(array $aArguments)
3333
}
3434

3535
/**
36-
* @param array $aArguments array of arguments to be parsed (@see $_SERVER['argv'])
36+
* @param array $arguments array of arguments to be parsed (@see $_SERVER['argv'])
3737
* @return array an associative array of key=>value arguments
3838
*/
39-
private function extractArguments(array $aArguments): array
39+
private function extractArguments(array $arguments): array
4040
{
4141
$aParsedArguments = [];
4242

43-
foreach ($aArguments as $sArgument) {
43+
foreach ($arguments as $sArgument) {
4444
// --foo --bar=baz
4545
if (substr($sArgument, 0, 2) == '--') {
4646
$sEqualPosition = strpos($sArgument, '=');

0 commit comments

Comments
 (0)