Skip to content

Commit 4705fb5

Browse files
authored
Fix double backslash in FunctionFirstClassCallableRector (#8398)
1 parent 4eca735 commit 4705fb5

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class LeadingBackslash
6+
{
7+
public function run(array $input)
8+
{
9+
return \array_map('\trim', $input);
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
18+
19+
final class LeadingBackslash
20+
{
21+
public function run(array $input)
22+
{
23+
return \array_map(\trim(...), $input);
24+
}
25+
}
26+
27+
?>

‎rules/CodingStyle/Rector/FuncCall/FunctionFirstClassCallableRector.php‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ public function refactor(Node $node): ?FuncCall
101101
continue;
102102
}
103103

104+
$isFullyQualified = str_starts_with($arg->value->value, '\\');
105+
$callableName = ltrim($arg->value->value, '\\');
106+
104107
$node->args[$key] = new Arg(
105108
new FuncCall(
106-
str_contains($arg->value->value, '\\')
107-
? new FullyQualified($arg->value->value)
108-
: new Name($arg->value->value),
109+
$isFullyQualified || str_contains($callableName, '\\')
110+
? new FullyQualified($callableName)
111+
: new Name($callableName),
109112
[new VariadicPlaceholder()]
110113
),
111114
name: $arg->name

0 commit comments

Comments
 (0)