Skip to content

Commit

Permalink
Merge branch 'rectorphp:main' into php84/rounding-modes-enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgsowa authored Dec 19, 2024
2 parents 4bce5ca + 6aca457 commit d77bfc9
Show file tree
Hide file tree
Showing 851 changed files with 11,754 additions and 3,696 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_scoped_rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ jobs:
# 3. prefix classes
- run: sh build/build-rector-scoped.sh rector-build rector-prefixed-downgraded

# 4. lint the code for PHP 7.2 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434
# 4. lint the code for PHP 7.4 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434
-
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 7.4
coverage: none
- run: composer global require php-parallel-lint/php-parallel-lint --ansi
- run: /home/runner/.composer/vendor/bin/parallel-lint rector-prefixed-downgraded --exclude rector-prefixed-downgraded/stubs --exclude rector-prefixed-downgraded/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded/vendor/rector/rector-generator/templates --exclude rector-prefixed-downgraded/vendor/symfony/console/Debug/CliRequest.php
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

-
name: 'PHPStan'
run: vendor/bin/phpstan analyse --ansi --error-format symplify
run: vendor/bin/phpstan analyse --ansi

-
name: 'Commented Code'
Expand All @@ -40,7 +40,7 @@ jobs:
-
name: 'Active Classes'
run: |
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector"
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector" --skip-type="Rector\\Set\\Contract\\SetListInterface"
-
name: 'Compatible PHPStan versions'
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
- 'e2e/invalid-paths'
- 'e2e/applied-polyfill-php80'
- 'e2e/print-new-node'
- 'e2e/only-option'
- 'e2e/only-option-quote-double-equalnone'
- 'e2e/only-option-quote-single'
- 'e2e/only-option-quote-single-bsdouble'
- 'e2e/only-option-quote-single-equalnone'

name: End to end test - ${{ matrix.directory }}

Expand Down
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ above commands in a docker container:

```bash
# Build the docker image
docker compose build
docker compose build --pull
# Install dependencies
docker compose run --rm php composer install
# Run the entire CI suite
docker compose run php composer complete-check
docker compose run --rm php composer complete-check
# Fix the coding standards
docker compose run php composer fix-cs
docker compose run --rm php composer fix-cs
```

## TroubleShooting
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8-cli-alpine
FROM php:8.2-cli-alpine

WORKDIR /etc/rector

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Head to [`rectorphp/rector`](http://github.com/rectorphp/rector) for documentati

## Building `rectorphp/rector`

Code of this repository requires PHP 8. For `rector/rector` package the build downgrades code to PHP 7.2+.
Code of this repository requires PHP 8. For `rector/rector` package the build downgrades code to PHP 7.4+.

<br>

Expand Down
95 changes: 95 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Upgrading from Rector 1.x to 2.0

## PHP version requirements

Rector now uses PHP 7.4 or newer to run.

<br>

## Rector now uses PHP-Parser 5

See [upgrading guide](https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md) for PHP-Parser.

<br>

## Rector now uses PHPStan 2

See [upgrading guide](https://github.com/phpstan/phpstan-src/blob/2.0.x/UPGRADING.md) for PHPStan.

<br>

## Upgrade for custom Rules writers

### 1. `AbstractScopeAwareRector` is removed, use `AbstractRector` instead

The `Rector\Rector\AbstractScopeAwareRector` was too granular to fetch single helper object. It made creating new custom rules ambiguous, one layer more complex and confusing. This class has been removed in favor of standard `AbstractRector`. The `Scope` object can be fetched via `ScopeFetcher`.

**Before**

```php
use Rector\Rector\AbstractScopeAwareRector;

final class SimpleRector extends AbstractScopeAwareRector
{
public function refactorWithScope(Node $node, Scope $scope): ?Node
{
// ...
}
}
```

**After**

```php
use Rector\Rector\AbstractRector;
use Rector\PHPStan\ScopeFetcher;

final class SimpleRector extends AbstractRector
{
public function refactor(Node $node): ?Node
{
if (...) {
// this allow to fetch scope only when needed
$scope = ScopeFetcher::fetch($node);
}

// ...
}
}
```


### 2. `AbstractRector` get focused on code, the `getRuleDefinition()` is no longer required

Core rules need documentation, so people can read their feature and [search through](https://getrector.com/find-rule) them. Yet for writing custom rules and local rules, its not necessary. People often filled it empty, just to make Rector happy.

This is no longer needed. Now The `getRuleDefinition()` method has been removed:

```diff
use Rector\Rector\AbstractRector;
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class SimpleRector extends AbstractRector
{
- public function getRuleDefinition(): RuleDefinition
- {
- return new RuleDefinition('// @todo fill the description', [
- new CodeSample(
- <<<'CODE_SAMPLE'
-// @todo fill code before
-CODE_SAMPLE
- ,
- <<<'CODE_SAMPLE'
-// @todo fill code after
-CODE_SAMPLE
- ),
- ]);
- }

// valuable code here
}
```

If you need description yourself to understand rule after many months, use the common place for documentation - docblock above class.

2 changes: 1 addition & 1 deletion bin/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function loadIfExistsAndNotLoadedYet(string $filePath): void
return;
}

/** @var string $realPath always string after file_exists() check */
/** @var non-empty-string $realPath always string after file_exists() check */
$realPath = realpath($filePath);
$this->alreadyLoadedAutoloadFiles[] = $realPath;

Expand Down
27 changes: 27 additions & 0 deletions build/build-preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class PreloadBuilder
'TokenEmulator.php',
'KeywordEmulator.php',
'Comment.php',
'PrettyPrinter.php',
'PrettyPrinterAbstract.php',
'Parser.php',
'ParserAbstract.php',
Expand Down Expand Up @@ -104,6 +105,21 @@ final class PreloadBuilder
'TypeNode.php',
];

/**
* The classes are deprecated and moved under Node
*
* @var string[]
*/
private const IN_USE_CLASS_FILES = [
'Node/Expr/ArrayItem.php',
'Node/Expr/ClosureUse.php',
'Node/Scalar/EncapsedStringPart.php',
'Node/Scalar/LNumber.php',
'Node/Stmt/DeclareDeclare.php',
'Node/Stmt/PropertyProperty.php',
'Node/Stmt/StaticVar.php',
];

public function buildPreloadScript(string $buildDirectory, string $preloadFile): void
{
$this->buildPreloadScriptPhpParser($buildDirectory, $preloadFile);
Expand Down Expand Up @@ -315,6 +331,17 @@ private function findPhpParserFilesAndSortThem(string $vendorDir): array
// 2. put first-class usages first
$fileInfos = $this->sortFileInfos($fileInfos);

foreach ($fileInfos as $key => $fileInfo) {
foreach (self::IN_USE_CLASS_FILES as $inUseClassFile) {
if (str_ends_with($fileInfo->getPathname(), $inUseClassFile)) {
unset($fileInfos[$key]);
continue 2;
}
}
}

$fileInfos = array_values($fileInfos);

$stmtsAwareInterface = new SplFileInfo(__DIR__ . '/../src/Contract/PhpParser/Node/StmtsAwareInterface.php');
array_splice($fileInfos, 1, 0, [$stmtsAwareInterface]);

Expand Down
2 changes: 1 addition & 1 deletion build/build-rector-scoped.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ composer remove ocramius/package-versions -W --update-no-dev --working-dir "$BUI

# Work around possible PHP memory limits
note "Running php-scoper on /bin, /config, /src, /rules and /vendor"
php -d memory_limit=-1 php-scoper.phar add-prefix bin config src rules vendor composer.json --output-dir "../$RESULT_DIRECTORY" --config scoper.php --force --ansi --working-dir "$BUILD_DIRECTORY";
php -d memory_limit=-1 php-scoper.phar add-prefix bin config src rules vendor composer.json UPGRADING.md --output-dir "../$RESULT_DIRECTORY" --config scoper.php --force --ansi --working-dir "$BUILD_DIRECTORY";

note "Dumping prefixed Composer Autoload"
composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev
Expand Down
2 changes: 1 addition & 1 deletion build/config/config-downgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
return RectorConfig::configure()
->withSkip(DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS)
->withPHPStanConfigs([__DIR__ . '/phpstan-for-downgrade.neon'])
->withDowngradeSets(php72: true);
->withDowngradeSets(php74: true);

/**
* Configuration consts for the different rector.php config files
Expand Down
4 changes: 0 additions & 4 deletions build/config/phpstan-for-downgrade.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ parameters:
scanDirectories:
# this is needed for symfony/dependendency-injection as it has hidden dependency on symfony/expression-language that we don't use here
- ../../stubs

# see https://github.com/rectorphp/rector/issues/3490#issue-634342324
featureToggles:
disableRuntimeReflectionProvider: true
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
commands:
-
name: 'Composer Dependency'
Expand All @@ -26,7 +26,7 @@ jobs:

-
name: 'Along PHPStan'
install: composer require phpstan/phpstan:^1.1.1 --dev --ansi
install: composer require phpstan/phpstan:^2.0 --dev --ansi

name: "PHP ${{ matrix.php_version }}"

Expand Down
2 changes: 1 addition & 1 deletion build/target-repository/.github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
directory:
- 'e2e/define-constant'
- 'e2e/dont-execute-code'
Expand Down
2 changes: 1 addition & 1 deletion build/target-repository/.github/workflows/e2e_diff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
directory:
- 'e2e/attributes'

Expand Down
2 changes: 1 addition & 1 deletion build/target-repository/.github/workflows/e2e_global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0', '8.1']
php_version: ['7.4', '8.0', '8.1']
directory:
- 'e2e/global-install'

Expand Down
31 changes: 0 additions & 31 deletions build/target-repository/.github/workflows/e2e_php72.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.3']
php_version: ['7.4']
directory:
- 'e2e/rector-prefixed-rule-test'

Expand Down
4 changes: 2 additions & 2 deletions build/target-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Rector instantly upgrades and refactors the PHP code of your application. It ca

### 1. Instant Upgrades

Rector now supports upgrades from PHP 5.3 to 8.2 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**?
Rector now supports upgrades from PHP 5.3 to 8.4 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), and [Doctrine](https://github.com/rectorphp/rector-doctrine). Do you want to **be constantly on the latest PHP and Framework without effort**?

Use Rector to handle **instant upgrades** for you.

Expand Down Expand Up @@ -162,4 +162,4 @@ We're using [ECS](https://github.com/symplify/easy-coding-standard) with [this s

### May cause unexpected output on File with mixed PHP+HTML content

When you apply changes to File(s) thas has mixed PHP+HTML content, you may need to manually verify the changed file after apply the changes.
When you apply changes to files with PHP + HTML content, you may need to manually verify the changed file after apply the changes.
4 changes: 2 additions & 2 deletions build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"bin/rector"
],
"require": {
"php": "^7.2|^8.0",
"phpstan/phpstan": "^1.12.5"
"php": "^7.4|^8.0",
"phpstan/phpstan": "^2.0.4"
},
"autoload": {
"files": [
Expand Down
11 changes: 0 additions & 11 deletions build/target-repository/e2e/reflection-union-php72/composer.json

This file was deleted.

17 changes: 0 additions & 17 deletions build/target-repository/e2e/reflection-union-php72/rector.php

This file was deleted.

Loading

0 comments on commit d77bfc9

Please sign in to comment.