Skip to content

Commit

Permalink
[Laravel] Add Laravel 6 instant upgrade set (#2195)
Browse files Browse the repository at this point in the history
[Laravel] Add Laravel 6 instant upgrade set
  • Loading branch information
TomasVotruba authored Oct 24, 2019
2 parents 080f07e + 99d30f3 commit 32a5e00
Show file tree
Hide file tree
Showing 53 changed files with 407 additions and 97 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"jetbrains/phpstorm-stubs": "^2019.1",
"mockery/mockery": "^1.2",
"ocramius/package-versions": "^1.4",
"phpunit/phpunit": "^7.5|^8.0",
"symplify/changelog-linker": "^6.1",
Expand Down
63 changes: 63 additions & 0 deletions config/set/laravel/laravel60.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# see https://laravel.com/docs/6.x/upgrade
services:
# https://github.com/laravel/docs/pull/5531/files
Rector\Rector\MethodCall\MethodCallToReturnRector:
Illuminate\Auth\Access\HandlesAuthorization:
- 'deny'

# https://github.com/laravel/framework/commit/67a38ba0fa2acfbd1f4af4bf7d462bb4419cc091
# covered by
Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector: ~

Rector\Renaming\Rector\MethodCall\RenameMethodRector:
# https://github.com/laravel/framework/commit/69de466ddc25966a0f6551f48acab1afa7bb9424
Illuminate\Auth\Access\Gate:
'access': 'inspect'

# https://github.com/laravel/framework/commit/efbe23c4116f86846ad6edc0d95cd56f4175a446
Illuminate\Support\Facades\Lang:
trans: 'get'
transChoice: 'choice'

# https://github.com/laravel/framework/commit/697b898a1c89881c91af83ecc4493fa681e2aa38
Illuminate\Translation\Translator:
getFromJson: 'get'

Rector\Renaming\Rector\MethodCall\RenameStaticMethodRector:
# https://github.com/laravel/framework/commit/55785d3514a8149d4858acef40c56a31b6b2ccd1
Illuminate\Support\Facades\Input:
get: ['Illuminate\Support\Facades\Request', 'input']

Rector\Renaming\Rector\Class_\RenameClassRector:
Illuminate\Support\Facades\Input: 'Illuminate\Support\Facades\Request'

Rector\Rector\Visibility\ChangeMethodVisibilityRector:
# https://github.com/laravel/framework/commit/e47e91417ab22e6af001db1dcbe75b87db218c1d
Illuminate\Foundation\Http\FormRequest:
validationData: 'public'

Rector\Rector\Argument\ArgumentAdderRector:
# https://github.com/laravel/framework/commit/6c1e014943a508afb2c10869c3175f7783a004e1
Illuminate\Database\Capsule\Manager:
table:
1:
name: 'as'
default_value: 'null'

Illuminate\Database\Connection:
table:
1:
name: 'as'
default_value: 'null'

Illuminate\Database\ConnectionInterface:
table:
1:
name: 'as'
default_value: 'null'

Illuminate\Database\Query\Builder:
from:
1:
name: 'as'
default_value: 'null'
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function matchTypeAndMethodName(MethodCall $methodCall): ?array
continue;
}

if (! $this->isNames($methodCall, $methodNames)) {
if (! $this->isNames($methodCall->name, $methodNames)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function matchTypeAndMethodName(MethodCall $methodCall): ?array
continue;
}

if (! $this->isNames($methodCall, $methodNames)) {
if (! $this->isNames($methodCall->name, $methodNames)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function getSetUuidMethodCallOnSameVariable(MethodCall $methodCall): ?Me
return false;
}

if (! $this->isName($node, 'setUuid')) {
if (! $this->isName($node->name, 'setUuid')) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($node, 'getRepository')) {
if (! $this->isName($node->name, 'getRepository')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($node, 'addFilter')) {
if (! $this->isName($node->name, 'addFilter')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function refactor(Node $node): ?Node
}

foreach ($methodsToArguments as $method => $argumentPosition) {
if (! $this->isName($node, $method)) {
if (! $this->isName($node->name, $method)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function processAboveTestInclude(Include_ $include): void

private function processUnderTestRun(MethodCall $methodCall): void
{
if ($this->isName($methodCall, 'run')) {
if ($this->isName($methodCall->name, 'run')) {
$this->removeNode($methodCall);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function collectTemplateFileNameAndVariables(ClassMethod $classMethod):
$this->templateVariables = [];

$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node): void {
if ($node instanceof MethodCall && $this->isName($node, 'render')) {
if ($node instanceof MethodCall && $this->isName($node->name, 'render')) {
$this->templateFileExpr = $node->args[0]->value;
$this->removeNode($node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function refactor(Node $node): ?Node
}

foreach ($this->addMethodToFormType as $method => $classType) {
if (! $this->isName($node, $method)) {
if (! $this->isName($node->name, $method)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($node, 'getHeader')) {
if (! $this->isName($node->name, 'getHeader')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($node, 'getParameter')) {
if (! $this->isName($node->name, 'getParameter')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function (Node $node, Foreach_ $foreachNode): ?Node {
return null;
}

if (! $this->isName($node, 'assertInstanceOf')) {
if (! $this->isName($node->name, 'assertInstanceOf')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function test()
{
$value = 'value';
$this->assertEquals('string', $value, 'message', 5.0);
$this->assertEquals('string', $value, 'message', 0.0, 20);
$this->assertEquals('string', $value, 'message', 0.0, 10, true);
$this->assertEquals('string', $value, 'message', 0.0, 10, false, true);
}
}
Expand All @@ -49,11 +49,11 @@ public function test()
{
$value = 'value';
$this->assertEqualsWithDelta('string', $value, 5.0, 'message');
$this->assertEquals('string', $value, 'message', 0.0);
$this->assertEqualsCanonicalizing('string', $value, 'message');
$this->assertEqualsIgnoringCase('string', $value, 'message');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($node, 'expects')) {
if (! $this->isName($node->name, 'expects')) {
return null;
}

Expand All @@ -88,7 +88,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isName($onlyArgument, 'any')) {
if (! $this->isName($onlyArgument->name, 'any')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function refactor(Node $node): ?Node

array_shift($node->args);

$methodName = $this->typeToMethod[$type][$this->isName($node, 'assertInternalType') ? 0 : 1];
$position = $this->isName($node->name, 'assertInternalType') ? 0 : 1;
$methodName = $this->typeToMethod[$type][$position];

$node->name = new Identifier($methodName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function refactor(Node $node): ?Node
return null;
}

if ($this->isName($node, 'with')) {
if ($this->isName($node->name, 'with')) {
return $this->processWithCall($node);
}

if ($this->isName($node, 'will')) {
if ($this->isName($node->name, 'will')) {
return $this->processWillCall($node);
}

Expand All @@ -105,8 +105,11 @@ public function refactor(Node $node): ?Node
private function processWithCall(Node $node): Node
{
foreach ($node->args as $i => $argNode) {
if ($argNode->value instanceof MethodCall && $this->isName($argNode->value, 'equalTo')) {
$node->args[$i] = $argNode->value->args[0];
if ($argNode->value instanceof MethodCall) {
$methodCall = $argNode->value;
if ($this->isName($methodCall->name, 'equalTo')) {
$node->args[$i] = $methodCall->args[0];
}
}
}

Expand All @@ -126,14 +129,16 @@ private function processWillCall(Node $node): ?Node
$nestedMethodCall = $node->args[0]->value;

foreach ($this->nestedMethodToRenameMap as $oldMethodName => $newParentMethodName) {
if ($this->isName($nestedMethodCall, $oldMethodName)) {
$node->name = new Identifier($newParentMethodName);
if (! $this->isName($nestedMethodCall->name, $oldMethodName)) {
continue;
}

// move args up
$node->args = $nestedMethodCall->args;
$node->name = new Identifier($newParentMethodName);

return $node;
}
// move args up
$node->args = $nestedMethodCall->args;

return $node;
}

return null;
Expand Down
14 changes: 7 additions & 7 deletions packages/PHPUnit/src/Rector/TryCatchToExpectExceptionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function processAssertInstanceOf(MethodCall $methodCall, Variable $varia
return;
}

if (! $this->isName($methodCall, 'assertInstanceOf')) {
if (! $this->isName($methodCall->name, 'assertInstanceOf')) {
return;
}

Expand All @@ -167,7 +167,7 @@ private function processExceptionMessage(MethodCall $methodCall, Variable $excep
return;
}

if (! $this->isNames($methodCall, ['assertSame', 'assertEquals'])) {
if (! $this->isNames($methodCall->name, ['assertSame', 'assertEquals'])) {
return;
}

Expand All @@ -180,7 +180,7 @@ private function processExceptionMessage(MethodCall $methodCall, Variable $excep
return;
}

if (! $this->isName($secondArgument, 'getMessage')) {
if (! $this->isName($secondArgument->name, 'getMessage')) {
return;
}

Expand All @@ -196,7 +196,7 @@ private function processExceptionCode(MethodCall $methodCall, Variable $exceptio
return;
}

if (! $this->isNames($methodCall, ['assertSame', 'assertEquals'])) {
if (! $this->isNames($methodCall->name, ['assertSame', 'assertEquals'])) {
return;
}

Expand All @@ -210,7 +210,7 @@ private function processExceptionCode(MethodCall $methodCall, Variable $exceptio
return;
}

if (! $this->isName($secondArgument, 'getCode')) {
if (! $this->isName($secondArgument->name, 'getCode')) {
return;
}

Expand All @@ -223,7 +223,7 @@ private function processExceptionMessageContains(MethodCall $methodCall, Variabl
return;
}

if (! $this->isName($methodCall, 'assertContains')) {
if (! $this->isName($methodCall->name, 'assertContains')) {
return;
}

Expand All @@ -237,7 +237,7 @@ private function processExceptionMessageContains(MethodCall $methodCall, Variabl
return;
}

if (! $this->isName($secondArgument, 'getMessage')) {
if (! $this->isName($secondArgument->name, 'getMessage')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private function isThisConstructCall(Node $node): bool
return false;
}

return $this->isName($node, '__construct');
return $this->isName($node->name, '__construct');
}

private function processParentPhp4ConstructCall(Node $node): void
Expand Down
2 changes: 1 addition & 1 deletion packages/PhpSpecToPHPUnit/src/LetManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function (Node $node): ?bool {
return null;
}

return $this->nameResolver->isName($node, 'beConstructedThrough');
return $this->nameResolver->isName($node->name, 'beConstructedThrough');
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function removeSelfTypeMethod(Class_ $node): Class_
continue;
}

if (! $this->isName($innerClassMethodStmt, 'shouldHaveType')) {
if (! $this->isName($innerClassMethodStmt->name, 'shouldHaveType')) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function processMethodParamsToMocks(ClassMethod $classMethod): void

private function processMethodCall(MethodCall $methodCall): ?MethodCall
{
if ($this->isName($methodCall, 'shouldBeCalled')) {
if ($this->isName($methodCall->name, 'shouldBeCalled')) {
if (! $methodCall->var instanceof MethodCall) {
throw new ShouldNotHappenException();
}
Expand Down
Loading

0 comments on commit 32a5e00

Please sign in to comment.