mirror of
https://github.com/rectorphp/rector.git
synced 2024-09-06 15:41:59 +00:00
Create new parameter method_if_no_args
, fix transforming back()
function, add back
file to test cases
https://github.com/rectorphp/rector/issues/1824
This commit is contained in:
parent
3c63fe10c3
commit
9806f6c564
@ -107,6 +107,7 @@ final class HelperFunctionToConstructorInjectionRector extends AbstractRector
|
||||
'type' => 'Illuminate\Routing\Redirector',
|
||||
'property' => 'redirector',
|
||||
'method_if_args' => 'back',
|
||||
'method_if_no_args' => 'back',
|
||||
],
|
||||
'broadcast' => [
|
||||
'type' => 'Illuminate\Contracts\Broadcasting\Factory',
|
||||
@ -231,6 +232,10 @@ CODE_SAMPLE
|
||||
$propertyFetchNode = $this->createPropertyFetch('this', $service['property']);
|
||||
|
||||
if (count($node->args) === 0) {
|
||||
if (isset($service['method_if_no_args'])) {
|
||||
return new MethodCall($propertyFetchNode, $service['method_if_no_args'], $node->args);
|
||||
}
|
||||
|
||||
return $propertyFetchNode;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,12 @@ class SomeBackController
|
||||
{
|
||||
public function action()
|
||||
{
|
||||
return back('template.blade');
|
||||
return back();
|
||||
}
|
||||
|
||||
public function actionWithParams()
|
||||
{
|
||||
return back(200);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,16 +24,21 @@ namespace Rector\Laravel\Tests\Rector\FuncCall\HelperFunctionToConstructorInject
|
||||
class SomeBackController
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Routing\UrlGenerator
|
||||
* @var \Illuminate\Routing\Redirector
|
||||
*/
|
||||
private $urlGenerator;
|
||||
public function __construct(\Illuminate\Routing\UrlGenerator $urlGenerator)
|
||||
private $redirector;
|
||||
public function __construct(\Illuminate\Routing\Redirector $redirector)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->redirector = $redirector;
|
||||
}
|
||||
public function action()
|
||||
{
|
||||
return $this->urlGenerator->route('template.blade');
|
||||
return $this->redirector->back();
|
||||
}
|
||||
|
||||
public function actionWithParams()
|
||||
{
|
||||
return $this->redirector->back(200);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ final class HelperFunctionToConstructorInjectionRectorTest extends AbstractRecto
|
||||
__DIR__ . '/Fixture/broadcast.php.inc',
|
||||
__DIR__ . '/Fixture/session.php.inc',
|
||||
__DIR__ . '/Fixture/route.php.inc',
|
||||
__DIR__ . '/Fixture/back.php.inc',
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user