diff --git a/README.md b/README.md
index 6cc40451..f0ca8ff2 100644
--- a/README.md
+++ b/README.md
@@ -31,9 +31,10 @@ return static function (RectorConfig $rectorConfig): void {
## Learn Rector Faster
-Rector is a tool that [we develop](https://getrector.org/) and share for free, so anyone can save hundreds of hours on refactoring. But not everyone has time to understand Rector and AST complexity. You have 2 ways to speed this process up:
+Rector is a tool that [we develop](https://getrector.org/) and share for free, so anyone can save hundreds of hours on refactoring.
+But not everyone has time to understand Rector and AST complexity. You have 2 ways to speed this process up:
-* read a book - The Power of Automated Refactoring
-* hire our experienced team to improve your codebase
+* Read the book - The Power of Automated Refactoring
+* Hire our experienced team to improve your codebase
Both ways support us to and improve Rector in sustainable way by learning from practical projects.
diff --git a/composer.json b/composer.json
index b9762529..1befb70b 100644
--- a/composer.json
+++ b/composer.json
@@ -37,8 +37,7 @@
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"docs": [
- "vendor/bin/rule-doc-generator generate src --output-file docs/rector_rules_overview.md --ansi",
- "vendor/bin/ecs check-markdown docs/rector_rules_overview.md --ansi --fix"
+ "vendor/bin/rule-doc-generator generate src --output-file docs/rector_rules_overview.md --ansi"
]
},
"minimum-stability": "dev",
diff --git a/config/sets/laravel-static-to-injection.php b/config/sets/laravel-static-to-injection.php
index aab7a81d..5a604e62 100644
--- a/config/sets/laravel-static-to-injection.php
+++ b/config/sets/laravel-static-to-injection.php
@@ -5,12 +5,12 @@
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
-use Rector\Transform\Rector\FuncCall\ArgumentFuncCallToMethodCallRector;
use Rector\Transform\Rector\FuncCall\FuncCallToNewRector;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall;
use Rector\Transform\ValueObject\ArrayFuncCallToMethodCall;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
+use RectorLaravel\Rector\FuncCall\ArgumentFuncCallToMethodCallRector;
use RectorLaravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
use RectorLaravel\Rector\StaticCall\RequestStaticValidateToInjectRector;
diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md
index a5246056..ab27b068 100644
--- a/docs/rector_rules_overview.md
+++ b/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 27 Rules Overview
+# 34 Rules Overview
## AddArgumentDefaultValueRector
@@ -9,9 +9,13 @@ Adds default value for arguments in defined methods.
- class: [`RectorLaravel\Rector\ClassMethod\AddArgumentDefaultValueRector`](../src/Rector/ClassMethod/AddArgumentDefaultValueRector.php)
```php
-use Rector\Config\RectorConfig;
+ruleWithConfiguration(AddArgumentDefaultValueRector::class, [
@@ -168,21 +172,164 @@ Convert migrations to anonymous classes.
+## ArgumentFuncCallToMethodCallRector
+
+Move help facade-like function calls to constructor injection
+
+:wrench: **configure it!**
+
+- class: [`RectorLaravel\Rector\FuncCall\ArgumentFuncCallToMethodCallRector`](../src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php)
+
+```php
+ruleWithConfiguration(ArgumentFuncCallToMethodCallRector::class, [
+ new ArgumentFuncCallToMethodCall('view', 'Illuminate\Contracts\View\Factory', 'make'),
+ ]);
+};
+```
+
+↓
+
+```diff
+ class SomeController
+ {
++ /**
++ * @var \Illuminate\Contracts\View\Factory
++ */
++ private $viewFactory;
++
++ public function __construct(\Illuminate\Contracts\View\Factory $viewFactory)
++ {
++ $this->viewFactory = $viewFactory;
++ }
++
+ public function action()
+ {
+- $template = view('template.blade');
+- $viewFactory = view();
++ $template = $this->viewFactory->make('template.blade');
++ $viewFactory = $this->viewFactory;
+ }
+ }
+```
+
+
+
## AssertStatusToAssertMethodRector
-Change `assertStatus($statusCode)` to the equivalent method `assertOk()` for example.
+Replace `(new \Illuminate\Testing\TestResponse)->assertStatus(200)` with `(new \Illuminate\Testing\TestResponse)->assertOk()`
- class: [`RectorLaravel\Rector\MethodCall\AssertStatusToAssertMethodRector`](../src/Rector/MethodCall/AssertStatusToAssertMethodRector.php)
```diff
- use Illuminate\Foundation\Testing\TestCase;
-
- final class SomeTest extends TestCase
+ class ExampleTest extends \Illuminate\Foundation\Testing\TestCase
{
- public function test(): void
+ public function testOk()
{
- $this->get('/')->assertStatus(200);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_OK);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_OK);
++ $this->get('/')->assertOk();
+ $this->get('/')->assertOk();
++ $this->get('/')->assertOk();
+ }
+
+ public function testNoContent()
+ {
+- $this->get('/')->assertStatus(204);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_NO_CONTENT);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NO_CONTENT);
++ $this->get('/')->assertNoContent();
++ $this->get('/')->assertNoContent();
++ $this->get('/')->assertNoContent();
+ }
+
+ public function testUnauthorized()
+ {
+- $this->get('/')->assertStatus(401);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_UNAUTHORIZED);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED);
++ $this->get('/')->assertUnauthorized();
++ $this->get('/')->assertUnauthorized();
++ $this->get('/')->assertUnauthorized();
+ }
+
+ public function testForbidden()
+ {
+- $this->get('/')->assertStatus(403);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_FORBIDDEN);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN);
++ $this->get('/')->assertForbidden();
++ $this->get('/')->assertForbidden();
++ $this->get('/')->assertForbidden();
+ }
+
+ public function testNotFound()
+ {
+- $this->get('/')->assertStatus(404);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_NOT_FOUND);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
++ $this->get('/')->assertNotFound();
++ $this->get('/')->assertNotFound();
++ $this->get('/')->assertNotFound();
+ }
+
+ public function testMethodNotAllowed()
+ {
+- $this->get('/')->assertStatus(405);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_METHOD_NOT_ALLOWED);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_METHOD_NOT_ALLOWED);
++ $this->get('/')->assertMethodNotAllowed();
++ $this->get('/')->assertMethodNotAllowed();
++ $this->get('/')->assertMethodNotAllowed();
+ }
+
+ public function testUnprocessableEntity()
+ {
+- $this->get('/')->assertStatus(422);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_UNPROCESSABLE_ENTITY);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY);
++ $this->get('/')->assertUnprocessable();
++ $this->get('/')->assertUnprocessable();
++ $this->get('/')->assertUnprocessable();
+ }
+
+ public function testGone()
+ {
+- $this->get('/')->assertStatus(410);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_GONE);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_GONE);
++ $this->get('/')->assertGone();
++ $this->get('/')->assertGone();
++ $this->get('/')->assertGone();
+ }
+
+ public function testInternalServerError()
+ {
+- $this->get('/')->assertStatus(500);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_INTERNAL_SERVER_ERROR);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR);
++ $this->get('/')->assertInternalServerError();
++ $this->get('/')->assertInternalServerError();
++ $this->get('/')->assertInternalServerError();
+ }
+
+ public function testServiceUnavailable()
+ {
+- $this->get('/')->assertStatus(503);
+- $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_SERVICE_UNAVAILABLE);
+- $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE);
++ $this->get('/')->asserServiceUnavailable();
++ $this->get('/')->asserServiceUnavailable();
++ $this->get('/')->asserServiceUnavailable();
}
}
```
@@ -270,15 +417,15 @@ Convert DB Expression `__toString()` calls to `getValue()` method calls.
## EmptyToBlankAndFilledFuncRector
-Convert `empty()` calls to `blank()` and `!empty()` calls to `filled()`.
+Replace use of the unsafe `empty()` function with Laravel's safer `blank()` & `filled()` functions.
-- class: [`RectorLaravel\Rector\FuncCall\EmptyToBlankAndFilledFuncRector`](../src/Rector/FuncCall/EmptyToBlankAndFilledFuncRector.php)
+- class: [`RectorLaravel\Rector\Empty_\EmptyToBlankAndFilledFuncRector`](../src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php)
```diff
--$empty = empty($value);
-+$empty = blank($value);
--$notEmpty = !empty($value);
-+$notEmpty = filled($value);
+-empty([]);
+-!empty([]);
++blank([]);
++filled([]);
```
@@ -441,38 +588,28 @@ Change minutes argument to seconds in `Illuminate\Contracts\Cache\Store` and Ill
## NotFilledBlankFuncCallToBlankFilledFuncCallRector
-Change `!blank()` func calls to `filled()` func calls and vice versa.
+Swap the use of NotBooleans used with `filled()` and `blank()` to the correct helper.
- class: [`RectorLaravel\Rector\FuncCall\NotFilledBlankFuncCallToBlankFilledFuncCallRector`](../src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php)
```diff
- class SomeClass
- {
- public function run()
- {
-- return !blank($value);
-+ return filled($value);
- }
- }
+-!filled([]);
+-!blank([]);
++blank([]);
++filled([]);
```
## NowFuncWithStartOfDayMethodCallToTodayFuncRector
-Changes the user of `now()->startOfDay()` to be replaced with `today()`.
+Use `today()` instead of `now()->startOfDay()`
- class: [`RectorLaravel\Rector\FuncCall\NowFuncWithStartOfDayMethodCallToTodayFuncRector`](../src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php)
```diff
-class SomeClass
-{
- public function run()
- {
-- now()->startOfDay();
-+ today();
- }
-}
+-$now = now()->startOfDay();
++$now = today();
```
@@ -486,12 +623,18 @@ Convert simple calls to optional helper to use the nullsafe operator
- class: [`RectorLaravel\Rector\PropertyFetch\OptionalToNullsafeOperatorRector`](../src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php)
```php
-use Rector\Config\RectorConfig;
+ruleWithConfiguration(OptionalToNullsafeOperatorRector::class, [
- OptionalToNullsafeOperatorRector::EXCLUDE_METHODS => ['present'],
+ OptionalToNullsafeOperatorRector::EXCLUDE_METHODS => [
+ 'present',
+ ],
]);
};
```
@@ -683,8 +826,12 @@ Use PHP callable syntax instead of string syntax for controller route declaratio
- class: [`RectorLaravel\Rector\StaticCall\RouteActionCallableRector`](../src/Rector/StaticCall/RouteActionCallableRector.php)
```php
-use Rector\Config\RectorConfig;
+ruleWithConfiguration(RouteActionCallableRector::class, [
diff --git a/src/Contract/ValueObject/ArgumentFuncCallToMethodCallInterface.php b/src/Contract/ValueObject/ArgumentFuncCallToMethodCallInterface.php
new file mode 100644
index 00000000..3df1c4a0
--- /dev/null
+++ b/src/Contract/ValueObject/ArgumentFuncCallToMethodCallInterface.php
@@ -0,0 +1,10 @@
+left, $node->right], function ($node) {
- return $node instanceof Expr\FuncCall && $this->isName($node, 'substr');
- }))[0] ?? null;
-
- if ($functionCall === null) {
+ $functionCall = array_values(
+ array_filter([$node->left, $node->right], fn ($node) => $node instanceof FuncCall && $this->isName(
+ $node,
+ 'substr'
+ ))
+ )[0] ?? null;
+
+ if (! $functionCall instanceof FuncCall) {
return null;
}
/** @var Expr $otherNode */
- $otherNode = array_values(array_filter([$node->left, $node->right], static function ($node) use ($functionCall) {
- return $node !== $functionCall;
- }))[0] ?? null;
+ $otherNode = array_values(
+ array_filter([$node->left, $node->right], static fn ($node) => $node !== $functionCall)
+ )[0] ?? null;
// get the function call second argument value
if (count($functionCall->getArgs()) < 2) {
@@ -68,7 +77,7 @@ public function refactor(Node $node): ?StaticCall
$secondArgument = $this->valueResolver->getValue($functionCall->getArgs()[1]->value);
- if (!is_int($secondArgument)) {
+ if (! is_int($secondArgument)) {
return null;
}
@@ -83,7 +92,8 @@ public function refactor(Node $node): ?StaticCall
}
return $this->nodeFactory->createStaticCall('Illuminate\Support\Str', $methodName, [
- $functionCall->getArgs()[0]->value,
+ $functionCall->getArgs()[0]
+->value,
$otherNode,
]);
}
diff --git a/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php b/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php
new file mode 100644
index 00000000..640f0663
--- /dev/null
+++ b/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php
@@ -0,0 +1,254 @@
+viewFactory = $viewFactory;
+ }
+
+ public function action()
+ {
+ $template = $this->viewFactory->make('template.blade');
+ $viewFactory = $this->viewFactory;
+ }
+}
+CODE_SAMPLE
+ ,
+ [new ArgumentFuncCallToMethodCall('view', 'Illuminate\Contracts\View\Factory', 'make')]
+ ),
+ ]);
+ }
+
+ /**
+ * @return array>
+ */
+ public function getNodeTypes(): array
+ {
+ return [FuncCall::class];
+ }
+
+ /**
+ * @param FuncCall $node
+ */
+ public function refactor(Node $node): ?Node
+ {
+ if ($this->shouldSkipFuncCall($node)) {
+ return null;
+ }
+
+ /** @var Class_ $classLike */
+ $classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
+
+ foreach ($this->argumentFuncCallToMethodCalls as $argumentFuncCallToMethodCall) {
+ if (! $this->isName($node, $argumentFuncCallToMethodCall->getFunction())) {
+ continue;
+ }
+
+ if ($argumentFuncCallToMethodCall instanceof ArgumentFuncCallToMethodCall) {
+ return $this->refactorFuncCallToMethodCall($argumentFuncCallToMethodCall, $classLike, $node);
+ }
+
+ if ($argumentFuncCallToMethodCall instanceof ArrayFuncCallToMethodCall) {
+ return $this->refactorArrayFunctionToMethodCall($argumentFuncCallToMethodCall, $node, $classLike);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param mixed[] $configuration
+ */
+ public function configure(array $configuration): void
+ {
+ Assert::allIsInstanceOf($configuration, ArgumentFuncCallToMethodCallInterface::class);
+
+ $this->argumentFuncCallToMethodCalls = $configuration;
+ }
+
+ private function shouldSkipFuncCall(FuncCall $funcCall): bool
+ {
+ // we can inject only in injectable class method context
+ /** @var ClassMethod|null $classMethod */
+ $classMethod = $this->betterNodeFinder->findParentType($funcCall, ClassMethod::class);
+ if (! $classMethod instanceof ClassMethod) {
+ return true;
+ }
+
+ return $classMethod->isStatic();
+ }
+
+ /**
+ * @return MethodCall|PropertyFetch|null
+ */
+ private function refactorFuncCallToMethodCall(
+ ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall,
+ Class_ $class,
+ FuncCall $funcCall
+ ): ?Node {
+ $fullyQualifiedObjectType = new FullyQualifiedObjectType($argumentFuncCallToMethodCall->getClass());
+ $expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType);
+
+ if (! $expectedName instanceof ExpectedName) {
+ throw new ShouldNotHappenException();
+ }
+
+ $propertyMetadata = new PropertyMetadata(
+ $expectedName->getName(),
+ $fullyQualifiedObjectType,
+ Class_::MODIFIER_PRIVATE
+ );
+ $this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
+
+ $propertyFetchNode = $this->nodeFactory->createPropertyFetch('this', $expectedName->getName());
+
+ if ($funcCall->args === []) {
+ return $this->refactorEmptyFuncCallArgs($argumentFuncCallToMethodCall, $propertyFetchNode);
+ }
+
+ if ($this->isFunctionToMethodCallWithArgs($funcCall, $argumentFuncCallToMethodCall)) {
+ $methodName = $argumentFuncCallToMethodCall->getMethodIfArgs();
+ if (! is_string($methodName)) {
+ throw new ShouldNotHappenException();
+ }
+
+ return new MethodCall($propertyFetchNode, $methodName, $funcCall->args);
+ }
+
+ return null;
+ }
+
+ /**
+ * @return PropertyFetch|MethodCall|null
+ */
+ private function refactorArrayFunctionToMethodCall(
+ ArrayFuncCallToMethodCall $arrayFuncCallToMethodCall,
+ FuncCall $funcCall,
+ Class_ $class
+ ): ?Node {
+ $propertyName = $this->propertyNaming->fqnToVariableName($arrayFuncCallToMethodCall->getClass());
+ $propertyFetch = $this->nodeFactory->createPropertyFetch('this', $propertyName);
+
+ $fullyQualifiedObjectType = new FullyQualifiedObjectType($arrayFuncCallToMethodCall->getClass());
+
+ $propertyMetadata = new PropertyMetadata($propertyName, $fullyQualifiedObjectType, Class_::MODIFIER_PRIVATE);
+ $this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
+
+ return $this->createMethodCallArrayFunctionToMethodCall(
+ $funcCall,
+ $arrayFuncCallToMethodCall,
+ $propertyFetch
+ );
+ }
+
+ private function refactorEmptyFuncCallArgs(
+ ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall,
+ PropertyFetch $propertyFetch
+ ): MethodCall | PropertyFetch {
+ if ($argumentFuncCallToMethodCall->getMethodIfNoArgs() !== null) {
+ $methodName = $argumentFuncCallToMethodCall->getMethodIfNoArgs();
+ return new MethodCall($propertyFetch, $methodName);
+ }
+
+ return $propertyFetch;
+ }
+
+ private function isFunctionToMethodCallWithArgs(
+ FuncCall $funcCall,
+ ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall
+ ): bool {
+ if ($argumentFuncCallToMethodCall->getMethodIfArgs() === null) {
+ return false;
+ }
+
+ return count($funcCall->args) >= 1;
+ }
+
+ /**
+ * @return PropertyFetch|MethodCall|null
+ */
+ private function createMethodCallArrayFunctionToMethodCall(
+ FuncCall $funcCall,
+ ArrayFuncCallToMethodCall $arrayFuncCallToMethodCall,
+ PropertyFetch $propertyFetch
+ ): ?Node {
+ if ($funcCall->getArgs() === []) {
+ return $propertyFetch;
+ }
+
+ if ($this->arrayTypeAnalyzer->isArrayType($funcCall->getArgs()[0]->value)) {
+ return new MethodCall($propertyFetch, $arrayFuncCallToMethodCall->getArrayMethod(), $funcCall->getArgs());
+ }
+
+ if ($arrayFuncCallToMethodCall->getNonArrayMethod() === '') {
+ return null;
+ }
+
+ return new MethodCall($propertyFetch, $arrayFuncCallToMethodCall->getNonArrayMethod(), $funcCall->getArgs());
+ }
+}
diff --git a/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php b/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php
index d55ee96b..2cde4563 100644
--- a/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php
+++ b/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php
@@ -1,9 +1,12 @@
expr instanceof Node\Expr\FuncCall) {
+ if (! $node->expr instanceof FuncCall) {
return null;
}
diff --git a/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php b/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php
index 7e4ffc0e..024f571c 100644
--- a/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php
+++ b/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php
@@ -1,8 +1,11 @@
startOfDay();
-CODE_SAMPLE,
+CODE_SAMPLE
+ ,
<<<'CODE_SAMPLE'
$now = today();
CODE_SAMPLE
@@ -35,7 +39,7 @@ public function getNodeTypes(): array
/**
* @param MethodCall $node
*/
- public function refactor(Node $node): ?Node\Expr\FuncCall
+ public function refactor(Node $node): ?FuncCall
{
if (! $this->isName($node->name, 'startOfDay')) {
return null;
diff --git a/src/ValueObject/ArgumentFuncCallToMethodCall.php b/src/ValueObject/ArgumentFuncCallToMethodCall.php
new file mode 100644
index 00000000..ad8e967a
--- /dev/null
+++ b/src/ValueObject/ArgumentFuncCallToMethodCall.php
@@ -0,0 +1,41 @@
+function;
+ }
+
+ public function getClass(): string
+ {
+ return $this->class;
+ }
+
+ public function getMethodIfNoArgs(): ?string
+ {
+ return $this->methodIfNoArgs;
+ }
+
+ public function getMethodIfArgs(): ?string
+ {
+ return $this->methodIfArgs;
+ }
+}
diff --git a/src/ValueObject/ArrayFuncCallToMethodCall.php b/src/ValueObject/ArrayFuncCallToMethodCall.php
new file mode 100644
index 00000000..53c9734c
--- /dev/null
+++ b/src/ValueObject/ArrayFuncCallToMethodCall.php
@@ -0,0 +1,49 @@
+function;
+ }
+
+ public function getClass(): string
+ {
+ return $this->class;
+ }
+
+ public function getArrayMethod(): string
+ {
+ return $this->arrayMethod;
+ }
+
+ public function getNonArrayMethod(): string
+ {
+ return $this->nonArrayMethod;
+ }
+}
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/ArgumentFuncCallToMethodCallRectorTest.php b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/ArgumentFuncCallToMethodCallRectorTest.php
new file mode 100644
index 00000000..09cfa6e3
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/ArgumentFuncCallToMethodCallRectorTest.php
@@ -0,0 +1,28 @@
+doTestFile($filePath);
+ }
+
+ public static function provideData(): Iterator
+ {
+ return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
+ }
+
+ public function provideConfigFilePath(): string
+ {
+ return __DIR__ . '/config/configured_rule.php';
+ }
+}
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/back.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/back.php.inc
new file mode 100644
index 00000000..865abe30
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/back.php.inc
@@ -0,0 +1,40 @@
+
+-----
+redirector->back();
+ }
+
+ public function actionWithParams()
+ {
+ return $this->redirector->back(200);
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/broadcast.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/broadcast.php.inc
new file mode 100644
index 00000000..e7d5e9d0
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/broadcast.php.inc
@@ -0,0 +1,30 @@
+
+-----
+broadcastingFactory->event('template.blade');
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/config.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/config.php.inc
new file mode 100644
index 00000000..9249f9ec
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/config.php.inc
@@ -0,0 +1,40 @@
+ $value]);
+ }
+}
+
+?>
+-----
+configRepository->get('value');
+ }
+
+ public function actionSet($value)
+ {
+ $this->configRepository->set(['value' => $value]);
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/route.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/route.php.inc
new file mode 100644
index 00000000..fa39ff7a
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/route.php.inc
@@ -0,0 +1,30 @@
+
+-----
+urlGenerator->route('template.blade');
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/session.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/session.php.inc
new file mode 100644
index 00000000..b092f650
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/session.php.inc
@@ -0,0 +1,34 @@
+
+-----
+sessionManager;
+ $this->sessionManager->put(['key']);
+ $this->sessionManager->get('key', 'value');
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/skip_static_method.php.inc b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/skip_static_method.php.inc
new file mode 100644
index 00000000..9017b1ff
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/Fixture/skip_static_method.php.inc
@@ -0,0 +1,11 @@
+
+-----
+viewFactory->make('template.blade');
+ $viewFactory = $this->viewFactory;
+ }
+}
+
+?>
diff --git a/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/config/configured_rule.php b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/config/configured_rule.php
new file mode 100644
index 00000000..d379d02a
--- /dev/null
+++ b/tests/Rector/FuncCall/ArgumentFuncCallToMethodCallRector/config/configured_rule.php
@@ -0,0 +1,21 @@
+ruleWithConfiguration(ArgumentFuncCallToMethodCallRector::class, [
+ new ArgumentFuncCallToMethodCall('view', 'Illuminate\Contracts\View\Factory', 'make'),
+ new ArgumentFuncCallToMethodCall('route', 'Illuminate\Routing\UrlGenerator', 'route'),
+ new ArgumentFuncCallToMethodCall('back', 'Illuminate\Routing\Redirector', 'back', 'back'),
+ new ArgumentFuncCallToMethodCall('broadcast', 'Illuminate\Contracts\Broadcasting\Factory', 'event'),
+
+ new ArrayFuncCallToMethodCall('config', 'Illuminate\Contracts\Config\Repository', 'set', 'get'),
+ new ArrayFuncCallToMethodCall('session', 'Illuminate\Session\SessionManager', 'put', 'get'),
+ ]);
+};
diff --git a/tests/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector/config/configured_rule.php b/tests/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector/config/configured_rule.php
index bac842e7..70ed29a4 100644
--- a/tests/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector/config/configured_rule.php
+++ b/tests/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector/config/configured_rule.php
@@ -4,8 +4,10 @@
use Rector\Config\RectorConfig;
+use RectorLaravel\Rector\FuncCall\NotFilledBlankFuncCallToBlankFilledFuncCallRector;
+
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../config/config.php');
- $rectorConfig->rule(\RectorLaravel\Rector\FuncCall\NotFilledBlankFuncCallToBlankFilledFuncCallRector::class);
+ $rectorConfig->rule(NotFilledBlankFuncCallToBlankFilledFuncCallRector::class);
};
diff --git a/tests/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector/config/configured_rule.php b/tests/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector/config/configured_rule.php
index addb73a7..b6dd6e5e 100644
--- a/tests/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector/config/configured_rule.php
+++ b/tests/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector/config/configured_rule.php
@@ -4,10 +4,10 @@
use Rector\Config\RectorConfig;
-use RectorLaravel\Rector\FuncCall\HelperFuncCallToFacadeClassRector;
+use RectorLaravel\Rector\FuncCall\NowFuncWithStartOfDayMethodCallToTodayFuncRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../config/config.php');
- $rectorConfig->rule(\RectorLaravel\Rector\FuncCall\NowFuncWithStartOfDayMethodCallToTodayFuncRector::class);
+ $rectorConfig->rule(NowFuncWithStartOfDayMethodCallToTodayFuncRector::class);
};
diff --git a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php
index 821bd94b..dcfb2847 100644
--- a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php
+++ b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php
@@ -5,13 +5,12 @@
namespace RectorLaravel\Tests\Rector\MethodCall\AssertStatusToAssertMethodRector;
use Iterator;
+use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class AssertStatusToAssertMethodTest extends AbstractRectorTestCase
{
- /**
- * @dataProvider provideData()
- */
+ #[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);