Skip to content

Commit

Permalink
Added rector and basic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Sep 19, 2024
1 parent bdcfba4 commit a7f4fbe
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 9 deletions.
1 change: 0 additions & 1 deletion .ddev/commands/web/rector
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
## Usage: rector
## Example: ddev rector <path-to-files>

cp -n vendor/sreichel/openmage-rector/rector.php rector.php
php vendor/bin/rector process "$@"
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.github export-ignore
/dev export-ignore
/docs export-ignore
/tests export-ignore

/.all-contributorsrc export-ignore
/.gitattributes export-ignore
Expand All @@ -16,6 +17,7 @@
/.phpmd.dist.xml export-ignore
/.phpstan.dist.baseline.neon export-ignore
/.phpstan.dist.neon export-ignore
/rector.php export-ignore

/README.md export-ignore

Expand Down
15 changes: 10 additions & 5 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,9 @@
'phpunit':
- changed-files:
- any-glob-to-any-file: [
dev/test/*,
dev/phpunit*,
dev/sonar*,
.github/workflows/phpunit.yml,
.github/workflows/sonar.yml
phpunit*,
tests/*,
.github/workflows/phpunit.yml
]

'ddev':
Expand All @@ -908,3 +906,10 @@
.ddev/*,
.ddev/**/*
]

'rector':
- changed-files:
- any-glob-to-any-file: [
rector.php,
.github/workflows/rector.yml
]
1 change: 1 addition & 0 deletions .github/workflows/check-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
**phpcs**
**php-cs-fixer**
**phpstan**
rector.php
tests/
phpunit*
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Rector

on:
workflow_call:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
rector:
name: Validation
runs-on: [ubuntu-latest]

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Checkout code
uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: Rector
run: php vendor/bin/rector process --dry-run
8 changes: 8 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ jobs:
if: needs.check.outputs.xml > 0
uses: ./.github/workflows/syntax-xml.yml

rector:
name: Rector
needs: [check, phpcs, php-cs-fixer]
if: |
needs.check.outputs.php > 0 ||
needs.check.outputs.workflow > 0
uses: ./.github/workflows/rector.yml

# DOES NOT run by default
# runs on schedule or when workflow or unit tests changed
unit_tests:
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^1.12.1",
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.2",
"squizlabs/php_codesniffer": "^3.7",
"symplify/vendor-patches": "^11.1"
},
Expand Down Expand Up @@ -134,14 +135,18 @@
"phpstan": "vendor/bin/phpstan analyze",
"phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --no-coverage --testdox",
"phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --testdox",
"phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox"
"phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html build/coverage --testdox",
"rector:test": "vendor/bin/rector process --dry-run",
"rector:fix": "vendor/bin/rector process"
},
"scripts-descriptions": {
"php-cs-fixer:test": "Run php-cs-fixer",
"php-cs-fixer:fix": "Run php-cs-fixer and fix issues",
"phpstan": "Run phpstan",
"phpunit:test": "Run PHPUnit",
"phpunit:coverage": "Run PHPUnit with code coverage",
"phpunit:coverage-local": "Run PHPUnit with local HTML code coverage"
"phpunit:coverage-local": "Run PHPUnit with local HTML code coverage",
"rector:test": "Run rector",
"rector:fix": "Run rector and fix issues"
}
}
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector as CodeQuality;
use Rector\DeadCode\Rector as DeadCode;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector as TypeDeclaration;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/app',
__DIR__ . '/dev',
__DIR__ . '/errors',
__DIR__ . '/lib',
__DIR__ . '/pub',
__DIR__ . '/shell',
__DIR__ . '/tests',
])
->withSkipPath(__DIR__ . '/vendor')
->withSkip([
__DIR__ . '/shell/translations.php',
__DIR__ . '/shell/update-copyright.php.php'
])
->withRules([
// CodeQuality\BooleanNot\SimplifyDeMorganBinaryRector::class, # wait for https://github.com/rectorphp/rector/issues/8781
CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class,
CodeQuality\Foreach_\UnusedForeachValueToArrayKeysRector::class,
CodeQuality\FuncCall\ChangeArrayPushToArrayAssignRector::class,
CodeQuality\FuncCall\CompactToVariablesRector::class,
CodeQuality\Identical\SimplifyArraySearchRector::class,
CodeQuality\Identical\SimplifyConditionsRector::class,
CodeQuality\Identical\StrlenZeroToIdenticalEmptyStringRector::class,
// CodeQuality\If_\SimplifyIfReturnBoolRector::class,
CodeQuality\NotEqual\CommonNotEqualRector::class,
CodeQuality\LogicalAnd\LogicalToBooleanRector::class,
CodeQuality\Ternary\SimplifyTautologyTernaryRector::class,
DeadCode\ClassMethod\RemoveUselessParamTagRector::class,
DeadCode\ClassMethod\RemoveUselessReturnTagRector::class,
DeadCode\Property\RemoveUselessVarTagRector::class,
TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class,
]);

0 comments on commit a7f4fbe

Please sign in to comment.