8000 [Php84] Skip with parentheses on class on NewMethodCallWithoutParenth… · rectorphp/rector-src@b38c275 · GitHub
[go: up one dir, main page]

Skip to content

Commit b38c275

Browse files
authored
[Php84] Skip with parentheses on class on NewMethodCallWithoutParenthesesRector (#6911)
* [Php84] Skip with parentheses on class on NewMethodCallWithoutParenthesesRector * clean
1 parent 48bc38b commit b38c275

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php84\Rector\MethodCall\NewMethodCallWithoutParenthesesRector\Fixture;
4+
5+
final class SkipWithParenthesesOnClass
6+
{
7+
public static function getGlobalSearchEloquentQuery(): Builder
8+
{
9+
return (new (static::getModel()))->newQuery()
10+
->orderByDesc('received_at');
11+
}
12+
}

rules/Php84/Rector/MethodCall/NewMethodCallWithoutParenthesesRector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public function refactor(Node $node): ?Node
5555

5656
$oldTokens = $this->file->getOldTokens();
5757

58+
$loop = 1;
59+
while (isset($oldT 8D1D okens[$node->var->getStartTokenPos() + $loop])) {
60+
if (trim((string) $oldTokens[$node->var->getStartTokenPos() + $loop]) === '') {
61+
++$loop;
62+
continue;
63+
}
64+
65+
if ((string) $oldTokens[$node->var->getStartTokenPos() + $loop] !== '(') {
66+
break;
67+
}
68+
69+
return null;
70+
}
71+
5872
// start node
5973
if (! isset($oldTokens[$node->getStartTokenPos()])) {
6074
return null;

0 commit comments

Comments
 (0)
0