-
Notifications
You must be signed in to change notification settings - Fork 0
Added Rector and CS-Fixer #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: PHP-CS-Fixer | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**.php' | ||
| - tools/php-cs-fixer/composer.json | ||
| - php-cs-fixer.php | ||
| - .github/workflows/php-cs-fixer.yml | ||
|
|
||
| jobs: | ||
| csfixer: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| php: ['8.2', '8.4'] | ||
| name: PHP-CS-Fixer (PHP ${{ matrix.php }}) | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php }} | ||
| coverage: none | ||
| env: | ||
| fail-fast: true | ||
|
|
||
| - 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('tools/php-cs-fixer/composer.json') }} | ||
| restore-keys: ${{ runner.os }}-composer- | ||
|
|
||
| - name: Install dependencies | ||
| run: composer composer-cs-fixer -- update --no-progress --prefer-dist | ||
|
|
||
| - name: Run PHP-CS-Fixer (dry-run) | ||
| run: composer cs-fixer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ jobs: | |
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| php-versions: ['8.1', '8.4'] | ||
| php-versions: ['8.2', '8.4'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep PHP 8.1 aus default minimum for now. |
||
| prefer: ['prefer-stable', 'prefer-lowest'] | ||
| name: PHPStan with PHP ${{ matrix.php-versions }} ${{ matrix.prefer }} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Rector | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**.php' | ||
| - tools/rector/composer.json | ||
| - rector.php | ||
| - .github/workflows/rector.yml | ||
|
|
||
| jobs: | ||
| rector: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| php: ['8.2', '8.4'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there different rules applied with PHP 8.2 and PHP 8.4? |
||
| name: Rector (PHP ${{ matrix.php }}) | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php }} | ||
| coverage: none | ||
| env: | ||
| fail-fast: true | ||
|
|
||
| - 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('tools/rector/composer.json') }} | ||
| restore-keys: ${{ runner.os }}-composer- | ||
|
|
||
| - name: Install dependencies | ||
| run: composer composer-rector -- update --no-progress --prefer-dist | ||
|
|
||
| - name: Run Rector (dry-run) | ||
| run: composer rector:test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| /.phpcs.cache | ||
| /.phpunit.result.cache | ||
| /.php-cs-fixer.cache | ||
| /.phpstan/ | ||
| /composer.lock | ||
| /phpstan.neon | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,6 +186,9 @@ Recommended approach: | |
| * Run `composer run -- phpstan --generate-baseline`. | ||
| * Include `phpstan-baseline.neon` in `phpstan.neon.dist`: | ||
| ``` | ||
| parameters: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall this indicate that |
||
| ... | ||
|
|
||
| includes: | ||
| - phpstan-baseline.neon | ||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| } | ||
| }, | ||
| "require": { | ||
| "php": "^8.1", | ||
| "php": "^8.2", | ||
| "civicrm/civicrm-core": ">={EXT_MIN_CIVICRM_VERSION}", | ||
| "civicrm/civicrm-packages": ">={EXT_MIN_CIVICRM_VERSION}" | ||
| }, | ||
|
|
@@ -39,7 +39,15 @@ | |
| "composer-phpunit": [ | ||
| "@composer --working-dir=tools/phpunit" | ||
| ], | ||
| "composer-rector": [ | ||
| "@composer --working-dir=tools/rector" | ||
| ], | ||
| "composer-cs-fixer": [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd name it |
||
| "@composer --working-dir=tools/php-cs-fixer" | ||
| ], | ||
| "composer-tools": [ | ||
| "@composer-cs-fixer", | ||
| "@composer-rector", | ||
| "@composer-phpcs", | ||
| "@composer-phpstan", | ||
| "@composer-phpunit" | ||
|
|
@@ -56,7 +64,26 @@ | |
| "phpunit": [ | ||
| "@php tools/phpunit/vendor/bin/simple-phpunit --coverage-text" | ||
| ], | ||
| "rector": [ | ||
| "@php tools/rector/vendor/bin/rector process" | ||
| ], | ||
| "rector:test": [ | ||
| "@php tools/rector/vendor/bin/rector process --dry-run" | ||
| ], | ||
| "cs-fixer": [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd name it I think it's not necessary to explicitly specify the config file. |
||
| "@php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=php-cs-fixer.php" | ||
| ], | ||
| "cs-fixer:test": [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd name it I think it's not necessary to explicitly specify the config file. |
||
| "@php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --config=php-cs-fixer.php" | ||
| ], | ||
| "fix": [ | ||
| "@rector", | ||
| "@cs-fixer", | ||
| "@phpcbf" | ||
| ], | ||
| "test": [ | ||
| "@rector:test", | ||
| "@cs-fixer:test", | ||
| "@phpcs", | ||
| "@phpstan", | ||
| "@phpunit" | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this file contains no placeholder the extension I think it should be named |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| use PhpCsFixer\Config; | ||
| use PhpCsFixer\Finder; | ||
|
|
||
| $finder = Finder::create() | ||
| ->in([ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The readme should be changed accordingly saying that this might need to be adapted. (Similar instructions already exist for the configurations of phpcs and phpstan.) |
||
| __DIR__ . '/CRM', | ||
| __DIR__ . '/Civi', | ||
| __DIR__ . '/api', | ||
| __DIR__ . '/tests', | ||
| ]) | ||
| ->exclude(['vendor', 'node_modules']); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering why this should be necessary. The given directories shouldn't be inside of any of the included directories. |
||
|
|
||
| return (new Config()) | ||
| ->setRiskyAllowed(TRUE) | ||
| ->setRules([ | ||
| 'declare_strict_types' => TRUE, | ||
| ]) | ||
| ->setFinder($finder); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| use Rector\Config\RectorConfig; | ||
| use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; | ||
| use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; | ||
| use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector; | ||
| use Rector\Set\ValueObject\SetList; | ||
| use Rector\ValueObject\PhpVersion; | ||
|
|
||
| return RectorConfig::configure() | ||
| ->withPaths([ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The readme should be changed accordingly saying that this might need to be adapted. (Similar instructions already exist for the configurations of phpcs and phpstan.) |
||
| __DIR__ . '/api', | ||
| __DIR__ . '/Civi', | ||
| __DIR__ . '/CRM', | ||
| __DIR__ . '/{EXT_SHORT_NAME}.php', | ||
| //__DIR__ . '/tests', | ||
| ]) | ||
| ->withSkip([ | ||
| __DIR__ . '/vendor', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This directory isn't part of |
||
| __DIR__ . '/CRM/*/DAO', | ||
| __DIR__ . '/CRM/*/DAO/*', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do this line and the one before behave differently? |
||
| __DIR__ . '/tools', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This directory isn't part of |
||
| ClassPropertyAssignToConstructorPromotionRector::class, | ||
| AddVoidReturnTypeWhereNoReturnRector::class, | ||
| ]) | ||
| ->withRules([ | ||
| SafeDeclareStrictTypesRector::class, | ||
| ]) | ||
| ->withSets([ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can understand the documentation indicates to use |
||
| SetList::CODE_QUALITY, | ||
| SetList::DEAD_CODE, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. phpstan also has some dead code checking. Does it make sense to additionally have this one? |
||
| //SetList::TYPE_DECLARATION, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have this line or should it be removed? |
||
| SetList::EARLY_RETURN, | ||
| ]) | ||
| ->withPhpVersion(PhpVersion::PHP_82) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't need this as the documentation says:
|
||
| ->withPhpSets(php82: true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could just use
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "require-dev": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case it's actually not a dev dependency. |
||
| "friendsofphp/php-cs-fixer": "^3.0" | ||
| }, | ||
| "config": { | ||
| "sort-packages": true | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "require-dev": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case it's actually not a dev dependency. |
||
| "rector/rector": "^2.3" | ||
| }, | ||
| "config": { | ||
| "sort-packages": true, | ||
| "allow-plugins": { | ||
| "dealerdirect/phpcodesniffer-composer-installer": true | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see the only rule enabled in the php-cs-fixer config is
declare_strict_types. In that case there's nothing that's not already checked by phpcs. So I'm wondering if it makes sense to have a GitHub workflow for php-cs-fixer.