Skip to content

Commit d0866a8

Browse files
authored
cover bare getters (#7467)
1 parent efcd5e9 commit d0866a8

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Fixture;
4+
5+
use CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Source\SomeGetter;
6+
7+
final class TwoBareGetters
8+
{
9+
public function run(SomeGetter $firstSomeGetter, SomeGetter $secondSomeGetter)
10+
{
11+
$first = $firstSomeGetter->getSome();
12+
$second = $secondSomeGetter->getSome();
13+
14+
return $first <=> $second;
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Tests\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Fixture;
23+
24+
use CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Source\SomeGetter;
25+
26+
final class TwoBareGetters
27+
{
28+
public function run(SomeGetter $firstSomeGetter, SomeGetter $secondSomeGetter)
29+
{
30+
return $firstSomeGetter->getSome() <=> $secondSomeGetter->getSome();
31+
}
32+
}
33+
34+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Source;
4+
5+
class SomeGetter
6+
{
7+
public function getSome()
8+
{
9+
return 100;
10+
}
11+
}

rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function matchToVariableAssignExpr(Stmt $stmt): ?VariableAndExprAssign
133133
}
134134

135135
// skip complex cases
136-
if ($assign->expr instanceof MethodCall) {
136+
if ($assign->expr instanceof MethodCall && $assign->expr->args !== []) {
137137
return null;
138138
}
139139

0 commit comments

Comments
 (0)