Skip to content

Commit 549f153

Browse files
authored
Merge branch 'main' into feature/declare-type-configs
2 parents c54d8f5 + 9959aaf commit 549f153

Some content is hidden

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

42 files changed

+568
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ return RectorConfig::configure()
4646
| [LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-legacy-factories-to-classes.php) | Migrates Eloquent legacy model factories (with closures) into class based factories.<br/>https://laravel.com/docs/8.x/releases#model-factory-classes |
4747
| [LaravelSetList::LARAVEL_STATIC_TO_INJECTION](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-static-to-injection.php) | Replaces Laravel's Facades with Dependency Injection.<br/>https://tomasvotruba.com/blog/2019/03/04/how-to-turn-laravel-from-static-to-dependency-injection-in-one-day/<br/>https://laravel.com/docs/11.x/facades#facades-vs-dependency-injection |
4848
| [LaravelSetList::LARAVEL_TYPE_DECLARATIONS](https://github.com/driftingly/rector-laravel/blob/main/config/sets/type-declaration.php) | Adds type hints to Closures and Arrow Functions where possible |
49+
| [LaravelSetList::LARAVEL_ARRAYACCESS_TO_METHOD_CALL](https://github.com/driftingly/rector-laravel/blob/main/config/sets/laravel-arrayaccess-to-method-call.php) | Converts uses of things like `$app['config']` to `$app->make('config')`. |
4950

5051
## Contributors
5152

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
use PHPStan\Type\ObjectType;
5+
use Rector\Config\RectorConfig;
6+
use Rector\Transform\Rector\ArrayDimFetch\ArrayDimFetchToMethodCallRector;
7+
use Rector\Transform\ValueObject\ArrayDimFetchToMethodCall;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->import(__DIR__ . '/../config.php');
11+
12+
$rectorConfig
13+
->ruleWithConfiguration(
14+
ArrayDimFetchToMethodCallRector::class,
15+
[
16+
new ArrayDimFetchToMethodCall(
17+
new ObjectType('Illuminate\Foundation\Application'),
18+
'make',
19+
),
20+
new ArrayDimFetchToMethodCall(
21+
new ObjectType('Illuminate\Config\Repository'),
22+
'get',
23+
),
24+
],
25+
);
26+
};

config/sets/laravel100.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
$rectorConfig
3636
->ruleWithConfiguration(RenamePropertyRector::class, [
3737
// https://github.com/laravel/laravel/commit/edcbe6de7c3f17070bf0ccaa2e2b785158ae5ceb
38-
new RenameProperty('App\Http\Kernel', 'routeMiddleware', 'middlewareAliases'),
38+
new RenameProperty('Illuminate\Foundation\Http\Kernel', 'routeMiddleware', 'middlewareAliases'),
3939
]);
4040

4141
$rectorConfig
4242
->ruleWithConfiguration(RenameMethodRector::class, [
4343
// https://github.com/laravel/framework/pull/42591/files
4444
new MethodCallRename('Illuminate\Support\Facades\Bus', 'dispatchNow', 'dispatchSync'),
45+
new MethodCallRename('Illuminate\Foundation\Bus\Dispatchable', 'dispatchNow', 'dispatchSync'),
46+
new MethodCallRename('Illuminate\Foundation\Bus\DispatchesJobs', 'dispatchNow', 'dispatchSync'),
4547
]);
4648

4749
$rectorConfig

config/sets/laravel90.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
6-
use Rector\Arguments\ValueObject\ArgumentAdder;
6+
use Rector\Arguments\ValueObject\ArgumentAdderWithoutDefaultValue;
77
use Rector\Config\RectorConfig;
88
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
99
use Rector\Renaming\ValueObject\MethodCallRename;
@@ -19,29 +19,27 @@
1919

2020
// https://github.com/laravel/framework/commit/8f9ddea4481717943ed4ecff96d86b703c81a87d
2121
$rectorConfig
22-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
22+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
2323
'Illuminate\Contracts\Foundation\Application',
2424
'storagePath',
2525
0,
2626
'path',
27-
''
2827
),
2928
]);
3029

3130
// https://github.com/laravel/framework/commit/e6c8aaea886d35cc55bd3469f1a95ad56d53e474
3231
$rectorConfig
33-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
32+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
3433
'Illuminate\Foundation\Application',
3534
'langPath',
3635
0,
3736
'path',
38-
''
3937
),
4038
]);
4139

4240
// https://github.com/laravel/framework/commit/e095ac0e928b5620f33c9b60816fde5ece867d32
4341
$rectorConfig
44-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
42+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
4543
'Illuminate\Database\Eloquent\Model',
4644
'touch',
4745
0,
@@ -51,7 +49,7 @@
5149

5250
// https://github.com/laravel/framework/commit/6daecf43dd931dc503e410645ff4a7d611e3371f
5351
$rectorConfig
54-
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdder(
52+
->ruleWithConfiguration(ArgumentAdderRector::class, [new ArgumentAdderWithoutDefaultValue(
5553
'Illuminate\Queue\Failed\FailedJobProviderInterface',
5654
'flush',
5755
0,

src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getNodeTypes(): array
7474
}
7575

7676
/**
77-
* @param Node\Stmt\Class_ $node
77+
* @param Class_ $node
7878
*/
7979
public function refactor(Node $node): ?Class_
8080
{

src/Rector/Expr/AppEnvironmentComparisonToParameterRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function refactor(Node $node): MethodCall|StaticCall|null
5151
return null;
5252
}
5353

54-
/** @var Node\Expr\MethodCall|Node\Expr\StaticCall|null $methodCall */
54+
/** @var MethodCall|StaticCall|null $methodCall */
5555
$methodCall = array_values(
5656
array_filter(
5757
[$node->left, $node->right],

src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getNodeTypes(): array
5151
}
5252

5353
/**
54-
* @param Node\Expr\FuncCall $node
54+
* @param FuncCall $node
5555
*/
5656
public function refactor(Node $node): ?Node
5757
{

src/Rector/FuncCall/SleepFuncToSleepStaticCallRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getNodeTypes(): array
4141
}
4242

4343
/**
44-
* @param Node\Stmt\Expression $node
44+
* @param Expression $node
4545
*/
4646
public function refactor(Node $node): ?Node
4747
{

src/Rector/MethodCall/EloquentWhereRelationTypeHintingParameterRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function changeClosureParamType(MethodCall|StaticCall $node): void
9696
['whereHasMorph', 'orWhereHasMorph', 'whereDoesntHaveMorph', 'orWhereDoesntHaveMorph']
9797
) ? 2 : 1;
9898

99-
/** @var Node\Expr\ArrowFunction|Node\Expr\Closure $closure */
99+
/** @var ArrowFunction|Closure $closure */
100100
$closure = $node->getArgs()[$position]
101101
->value;
102102

src/Rector/MethodCall/EloquentWhereTypeHintClosureParameterRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function isWhereMethodWithClosureOrArrowFunction(MethodCall|StaticCall $
7777

7878
private function changeClosureParamType(MethodCall|StaticCall $node): void
7979
{
80-
/** @var Node\Expr\ArrowFunction|Node\Expr\Closure $closure */
80+
/** @var ArrowFunction|Closure $closure */
8181
$closure = $node->getArgs()[0]
8282
->value;
8383

0 commit comments

Comments
 (0)