Skip to content

Commit 603e154

Browse files
authored
Merge branch 'rectorphp:main' into feature/remove-void-from-magic-methods-as-return
2 parents cfd2280 + afd6b04 commit 603e154

File tree

470 files changed

+6824
-12986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

470 files changed

+6824
-12986
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
-
5252
name: 'Finalize classes'
53-
run: vendor/bin/swiss-knife finalize-classes src tests rules --dry-run
53+
run: vendor/bin/swiss-knife finalize-classes src tests rules --dry-run --skip-file="src/PhpParser/Node/FileNode.php"
5454

5555
-
5656
name: 'Check before/after test fixture on no-changes'

.github/workflows/lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Lock closed PRs"
22

33
on:
44
schedule:
5-
- cron: "0 3 * * *" # every day at 03:00 UTC
5+
- cron: "0 3 * * 0" # every Sunday at 03:00 UTC
66
workflow_dispatch:
77

88
jobs:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: PHPStan Printer Test
2+
3+
on:
4+
pull_request: null
5+
push:
6+
branches:
7+
- main
8+
9+
10+
11+
env:
12+
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
13+
COMPOSER_ROOT_VERSION: "dev-main"
14+
15+
jobs:
16+
tests:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, windows-latest]
21+
php-versions: ['8.2']
22+
23+
runs-on: ${{ matrix.os }}
24+
timeout-minutes: 3
25+
26+
name: PHP ${{ matrix.php-versions }} tests (${{ matrix.os }})
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
-
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-versions }}
34+
coverage: none
35+
# to display warning when assert() is called, eg: on direct getArgs() on CallLike
36+
# and check against first class callable strlen(...)
37+
ini-values: zend.assertions=1
38+
39+
- uses: "ramsey/composer-install@v3"
40+
41+
- run: vendor/bin/phpunit tests/PhpParser/Printer/PHPStanPrinterTest.php --colors
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Rector Laravel with dev-main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: null
8+
9+
env:
10+
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
11+
COMPOSER_ROOT_VERSION: "dev-main"
12+
13+
jobs:
14+
rector_laravel_rector_dev:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
-
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 8.3
22+
coverage: none
23+
24+
# fixes https://github.com/rectorphp/rector/pull/4559/checks?check_run_id=1359814403, see https://github.com/shivammathur/setup-php#composer-github-oauth
25+
env:
26+
COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN }}
27+
28+
- run: git clone https://github.com/driftingly/rector-laravel.git
29+
- run: composer require rector/rector:dev-main --working-dir rector-laravel
30+
- run: cd rector-laravel && vendor/bin/phpunit
31+

UPGRADING.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,110 @@
1+
# Upgrading from Rector 2.2.14 to 2.3
2+
3+
* `FileWithoutNamespace` is deprecated, and replaced by `FileNode` that represents both namespaced and non-namespaced files and allow changes inside
4+
* `beforeTraverse()` is now marked as `@final`, use `getNodeTypes()` with `FileNode::class` instead
5+
6+
**Before**
7+
8+
```php
9+
use Rector\PhpParser\Node\FileWithoutNamespace;
10+
use Rector\Rector\AbstractRector;
11+
12+
final class SomeRector extends AbstractRector
13+
{
14+
public function getNodeTypes(): array
15+
{
16+
return [FileWithoutNamespace::class];
17+
}
18+
19+
public function beforeTraverse(array $nodes): array
20+
{
21+
// some node hacking
22+
}
23+
24+
/**
25+
* @param FileWithoutNamespace $node
26+
*/
27+
public function refactor(Node $node): ?Node
28+
{
29+
// ...
30+
}
31+
32+
}
33+
```
34+
35+
**After**
36+
37+
```php
38+
use Rector\PhpParser\Node\FileNode;
39+
use Rector\Rector\AbstractRector;
40+
41+
final class SomeRector extends AbstractRector
42+
{
43+
public function getNodeTypes(): array
44+
{
45+
return [FileNode::class];
46+
}
47+
48+
/**
49+
* @param FileNode $node
50+
*/
51+
public function refactor(Node $node): ?Node
52+
{
53+
foreach ($node->stmts as $stmt) {
54+
// check if has declare_strict already?
55+
// ...
56+
57+
// create it
58+
$declareStrictTypes = $this->createDeclareStrictTypesNode();
59+
60+
// add it
61+
$node->stmts = array_merge([$declareStrictTypes], $node->stmts);
62+
}
63+
64+
return $node;
65+
}
66+
67+
}
68+
```
69+
70+
<br>
71+
72+
The `FileNode` handles both namespaced and non-namespaced files. To handle the first stmts inside the file, you hook into 2 nodes:
73+
74+
```php
75+
use Rector\PhpParser\Node\FileNode;
76+
use Rector\Rector\AbstractRector;
77+
use PhpParser\Node\Stmt\Namespace_;
78+
79+
final class SomeRector extends AbstractRector
80+
{
81+
public function getNodeTypes(): array
82+
{
83+
return [FileNode::class, Namespace_::class];
84+
}
85+
86+
/**
87+
* @param FileNode|Namespace_ $node
88+
*/
89+
public function refactor(Node $node): ?Node
90+
{
91+
if ($node instanceof FileNode && $node->isNamespaced()) {
92+
// handled in the Namespace_ node
93+
return null;
94+
}
95+
96+
foreach ($node->stmts as $stmt) {
97+
// modify stmts in desired way here
98+
}
99+
100+
return $node;
101+
}
102+
103+
}
104+
```
105+
106+
<br>
107+
1108
# Upgrading from Rector 1.x to 2.0
2109

3110
## PHP version requirements

build/target-repository/.github/workflows/lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "Lock closed issues"
22

33
on:
44
schedule:
5-
- cron: "0 3 * * *" # every day at 03:00 UTC
5+
- cron: "0 3 * * 0" # every Sunday at 03:00 UTC
66
workflow_dispatch:
77

88
jobs:

build/target-repository/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"require": {
1111
"php": "^7.4|^8.0",
12-
"phpstan/phpstan": "^2.1.32"
12+
"phpstan/phpstan": "^2.1.33"
1313
},
1414
"autoload": {
1515
"files": [

0 commit comments

Comments
 (0)