Skip to content

Commit 7bb8e3c

Browse files
authored
HelperFuncCallToFacadeClassRector, allow with argument (#318)
* HelperFuncCallToFacadeClassRector, allow with argument * Skip in case of no argument
1 parent 40bbddd commit 7bb8e3c

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

Diff for: src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SomeClass
3838
{
3939
public function run()
4040
{
41-
return \Illuminate\Support\Facades\App::get('translator')->trans('value');
41+
return \Illuminate\Support\Facades\App::make('translator')->trans('value');
4242
}
4343
}
4444
CODE_SAMPLE
@@ -59,14 +59,14 @@ public function getNodeTypes(): array
5959
*/
6060
public function refactor(Node $node): ?Node
6161
{
62-
if (! $this->isName($node->name, 'app')) {
62+
if (! $this->isNames($node->name, ['app', 'resolve'])) {
6363
return null;
6464
}
6565

66-
if (count($node->args) !== 1) {
67-
return null;
66+
if (count($node->args) > 0) {
67+
return $this->nodeFactory->createStaticCall('Illuminate\Support\Facades\App', 'make', $node->args);
6868
}
6969

70-
return $this->nodeFactory->createStaticCall('Illuminate\Support\Facades\App', 'get', $node->args);
70+
return null;
7171
}
7272
}

Diff for: tests/Rector/FuncCall/HelperFuncCallToFacadeClassRector/Fixture/fixture.php.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Fixture
2020
{
2121
public function run()
2222
{
23-
return \Illuminate\Support\Facades\App::get('translator')->trans('value');
23+
return \Illuminate\Support\Facades\App::make('translator')->trans('value');
2424
}
2525
}
2626

Diff for: tests/Rector/FuncCall/HelperFuncCallToFacadeClassRector/Fixture/skip_with_args.php.inc renamed to tests/Rector/FuncCall/HelperFuncCallToFacadeClassRector/Fixture/skip_with_no_arg.php.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace RectorLaravel\Tests\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
44

5-
class SkipWithArgs
5+
class SkipWithNoArg
66
{
77
public function run()
88
{
9-
return app('translator', 'some');
9+
return app()->isProduction();
1010
}
1111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
4+
5+
class WithArgs
6+
{
7+
public function run()
8+
{
9+
resolve(SomeClass::class, ['argument' => 'value']);
10+
11+
return app(OtherClass::class, ['argument' => 'value']);
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace RectorLaravel\Tests\Rector\FuncCall\HelperFuncCallToFacadeClassRector\Fixture;
20+
21+
class WithArgs
22+
{
23+
public function run()
24+
{
25+
\Illuminate\Support\Facades\App::make(SomeClass::class, ['argument' => 'value']);
26+
27+
return \Illuminate\Support\Facades\App::make(OtherClass::class, ['argument' => 'value']);
28+
}
29+
}
30+
31+
?>

0 commit comments

Comments
 (0)