Skip to content

AC-1740: Add rectorphp as a dependency to magento-coding-standard #333

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

Merged
merged 20 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d3dc3f4
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
874884f
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
cdf641e
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
b669d8c
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
372da91
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
503878b
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
01e243e
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
cda190f
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 16, 2021
a4595df
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 17, 2021
f7fdb02
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 17, 2021
a18b7f2
AC-1740: Add rectorphp as a dependency to magento-coding-standard
eliseacornejo Nov 18, 2021
02eb5d8
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Nov 18, 2021
a5ad00b
AC-1740
eliseacornejo Nov 19, 2021
2915b71
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Nov 19, 2021
5ebccb0
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 19, 2021
d463a5a
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 19, 2021
4b3df3e
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 22, 2021
692b23d
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 22, 2021
a10e77c
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 23, 2021
856d8ca
AC-1740: Add rectorphp as a dependency to magento-coding-standard and…
eliseacornejo Nov 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,20 @@ jobs:

- name: Run ESLint
run: npm run eslint -- eslint/rules
rector:
runs-on: ubuntu-latest
name: Rector tests

steps:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16'

- uses: actions/checkout@v2

- name: Install dependencies
run: composer install

- name: Run rector
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ You can execute ESLint as follows:
npm run eslint -- path/to/analyze
```

### RECTOR PHP
From `magento-condign-standard` project, you can execute rector php as follows:
```bash
vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php
```
The rules from rector that are applied are set inside the config file: `rector.php`

The option `--dry-run` displays errors found, but code is not automatically fixed.

To run rector for `magento` projects you need to:
- Specify the magento path and the autoload file for the magento project:
```bash
vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE
```
Example:
```bash
vendor/bin/rector process magento2ce/app/code/Magento/Cms/Model --dry-run --autoload-file magento2ce/vendor/autoload.php
```

## License

Each Magento source file included in this distribution is licensed under the OSL-3.0 license.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"ext-simplexml": "*",
"ext-dom": "*",
"phpcompatibility/php-compatibility": "^9.3",
"squizlabs/php_codesniffer": "^3.6"
"squizlabs/php_codesniffer": "^3.6",
"rector/rector": "^0.12.4"
},
"require-dev": {
"phpunit/phpunit": "^9.5.8"
Expand Down
126 changes: 125 additions & 1 deletion composer.lock

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

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

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php80\Rector\Class_\StringableForToStringRector;
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
use Rector\Php80\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
use Rector\Php81\Rector\FuncCall\Php81ResourceReturnToObjectRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_81);

// get services (needed for register a single rule)
$services = $containerConfigurator->services();

// register a single rule
$services->set(FinalPrivateToPrivateVisibilityRector::class);
$services->set(OptionalParametersAfterRequiredRector::class);
$services->set(SetStateToStaticRector::class);
$services->set(StringableForToStringRector::class);
$services->set(Php81ResourceReturnToObjectRector::class);
};