Skip to content

Commit cff29ea

Browse files
committed
register rule
1 parent 511b10f commit cff29ea

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector\Fixture;
4+
5+
final class SkipMethodCallsToKeepReadability
6+
{
7+
public function run()
8+
{
9+
$first = $this->createLongValue(100);
10+
$second = $this->createLongValue(200);
11+
12+
return $first <=> $second;
13+
}
14+
15+
private function createLongValue($value)
16+
{
17+
return $value . ' is long';
18+
}
19+
}

rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Expr\Assign;
99
use PhpParser\Node\Expr\BinaryOp;
1010
use PhpParser\Node\Expr\Closure;
11+
use PhpParser\Node\Expr\MethodCall;
1112
use PhpParser\Node\Expr\Variable;
1213
use PhpParser\Node\Stmt;
1314
use PhpParser\Node\Stmt\ClassMethod;
@@ -131,6 +132,11 @@ private function matchToVariableAssignExpr(Stmt $stmt): ?VariableAndExprAssign
131132
return null;
132133
}
133134

135+
// skip complex cases
136+
if ($assign->expr instanceof MethodCall) {
137+
return null;
138+
}
139+
134140
return new VariableAndExprAssign($assign->var, $assign->expr);
135141
}
136142
}

src/Config/Level/CodingStyleLevel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
99
use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector;
1010
use Rector\CodingStyle\Rector\ClassConst\SplitGroupedClassConstantsRector;
11+
use Rector\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector;
1112
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
1213
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
1314
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
@@ -77,6 +78,7 @@ final class CodingStyleLevel
7778
SplitGroupedClassConstantsRector::class,
7879
ExplicitPublicClassMethodRector::class,
7980
RemoveUselessAliasInUseStatementRector::class,
81+
BinaryOpStandaloneAssignsToDirectRector::class,
8082
];
8183

8284
/**

0 commit comments

Comments
 (0)