Skip to content

Commit 9306801

Browse files
committed
Allow to rename function and method arguments
1 parent 746d697 commit 9306801

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

features/rename_local_variable.feature

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,46 @@ Feature: Rename Local Variable
9191
9292
"""
9393

94+
Scenario: Rename a method argument
95+
Given a PHP File named "src/MethodArgument.php" with:
96+
"""
97+
<?php
98+
class MethodArgument
99+
{
100+
public function operation($varsecond = 5)
101+
{
102+
$var = 2;
103+
104+
return $var + $varsecond;
105+
}
106+
}
107+
"""
108+
When I use refactoring "rename-local-variable" with:
109+
| arg | value |
110+
| file | src/MethodArgument.php |
111+
| line | 4 |
112+
| name | varsecond |
113+
| new-name | multiplier |
114+
Then the PHP File "src/MethodArgument.php" should be refactored:
115+
"""
116+
--- a/vfs://project/src/MethodArgument.php
117+
+++ b/vfs://project/src/MethodArgument.php
118+
@@ -1,10 +1,10 @@
119+
<?php
120+
class MethodArgument
121+
{
122+
- public function operation($varsecond = 5)
123+
+ public function operation($multiplier = 5)
124+
{
125+
$var = 2;
126+
127+
- return $var + $varsecond;
128+
+ return $var + $multiplier;
129+
}
130+
}
131+
132+
"""
133+
94134
Scenario: Rename Variable In functions
95135
Given a PHP File named "src/Foo.php" with:
96136
"""
@@ -131,4 +171,44 @@ Feature: Rename Local Variable
131171
- return $var * $var;
132172
+ return $number * $number;
133173
}
174+
"""
175+
176+
Scenario: Rename a function's parameter
177+
Given a PHP File named "src/Foo.php" with:
178+
"""
179+
<?php
180+
function operation($number)
181+
{
182+
$var = 2;
183+
184+
for ($i = 0; $i < 3; $i++) {
185+
$var = pow($var, $number);
186+
}
187+
188+
return $var * $var;
189+
}
190+
"""
191+
When I use refactoring "rename-local-variable" with:
192+
| arg | value |
193+
| file | src/Foo.php |
194+
| line | 2 |
195+
| name | number |
196+
| new-name | power |
197+
Then the PHP File "src/Foo.php" should be refactored:
198+
"""
199+
--- a/vfs://project/src/Foo.php
200+
+++ b/vfs://project/src/Foo.php
201+
@@ -1,10 +1,10 @@
202+
<?php
203+
-function operation($number)
204+
+function operation($power)
205+
{
206+
$var = 2;
207+
208+
for ($i = 0; $i < 3; $i++) {
209+
- $var = pow($var, $number);
210+
+ $var = pow($var, $power);
211+
}
212+
213+
return $var * $var;
134214
"""

src/main/QafooLabs/Refactoring/Adapters/TokenReflection/StaticCodeAnalysis.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private function findMatchingMethod(File $file, LineRange $range)
159159
foreach ($file->getNamespaces() as $namespace) {
160160
foreach ($namespace->getClasses() as $class) {
161161
foreach ($class->getMethods() as $method) {
162-
if ($method->getStartLine() < $lastLine && $lastLine < $method->getEndLine()) {
162+
if ($method->getStartLine() <= $lastLine && $lastLine <= $method->getEndLine()) {
163163
$foundMethod = $method;
164164
break;
165165
}
@@ -180,7 +180,7 @@ private function findMatchingFunction(File $file, LineRange $range)
180180

181181
foreach ($file->getNamespaces() as $namespace) {
182182
foreach ($namespace->getFunctions() as $function) {
183-
if ($function->getStartLine() < $lastLine && $lastLine < $function->getEndLine()) {
183+
if ($function->getStartLine() <= $lastLine && $lastLine <= $function->getEndLine()) {
184184
$foundFunction = $function;
185185
break;
186186
}

0 commit comments

Comments
 (0)