Skip to content

Commit 63f11e9

Browse files
committed
Detect method name case changes
1 parent a382291 commit 63f11e9

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/PHPSemVerChecker/Comparator/Signature.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@ public static function analyze(FunctionLike $functionA, FunctionLike $functionB)
2222
'parameter_default_value_changed' => false,
2323
];
2424

25+
$changes = self::detectFunctionNameChanges($changes, $functionA, $functionB);
2526
$changes = self::detectParameterChanges($changes, $functionA, $functionB);
2627

2728
return $changes;
2829
}
2930

31+
private static function detectFunctionNameChanges($changes, FunctionLike $functionA, FunctionLike $functionB)
32+
{
33+
if ($functionA->name != $functionB->name) {
34+
35+
if (strtolower($functionA->name) == strtolower($functionB->name)) {
36+
$changes['function_renamed_case_only'] = true;
37+
} else {
38+
$changes['function_renamed'] = true;
39+
}
40+
41+
return $changes;
42+
}
43+
44+
return $changes;
45+
}
46+
3047
private static function detectParameterChanges($changes, FunctionLike $functionA, FunctionLike $functionB)
3148
{
3249
$parametersA = $functionA->getParams();

tests/PHPSemVerChecker/Comparator/SignatureTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,70 @@ public function testAddedParameters()
9797

9898
$this->assertEquals($expectedResult, $result);
9999
}
100+
101+
public function testMethodRenamed()
102+
{
103+
$signature1 = new ClassMethod('testMethod1', [
104+
'params' => [
105+
new Param('testParameter'),
106+
],
107+
]);
108+
109+
110+
$signature2 = new ClassMethod('testMethodRenamed', [
111+
'params' => [
112+
new Param('testParameter'),
113+
],
114+
]);
115+
116+
$result = Signature::analyze($signature1, $signature2);
117+
118+
$expectedResult = [
119+
'function_renamed' => true,
120+
'function_renamed_case_only' => false,
121+
'parameter_added' => false,
122+
'parameter_removed' => false,
123+
'parameter_renamed' => false,
124+
'parameter_typing_added' => false,
125+
'parameter_typing_removed' => false,
126+
'parameter_default_added' => false,
127+
'parameter_default_removed' => false,
128+
'parameter_default_value_changed' => false,
129+
];
130+
131+
$this->assertEquals($expectedResult, $result);
132+
}
133+
134+
public function testMethodRenamedCaseOnly()
135+
{
136+
$signature1 = new ClassMethod('testMethodOne', [
137+
'params' => [
138+
new Param('testParameter'),
139+
],
140+
]);
141+
142+
143+
$signature2 = new ClassMethod('testmethodone', [
144+
'params' => [
145+
new Param('testParameter'),
146+
],
147+
]);
148+
149+
$result = Signature::analyze($signature1, $signature2);
150+
151+
$expectedResult = [
152+
'function_renamed' => false,
153+
'function_renamed_case_only' => true,
154+
'parameter_added' => false,
155+
'parameter_removed' => false,
156+
'parameter_renamed' => false,
157+
'parameter_typing_added' => false,
158+
'parameter_typing_removed' => false,
159+
'parameter_default_added' => false,
160+
'parameter_default_removed' => false,
161+
'parameter_default_value_changed' => false,
162+
];
163+
164+
$this->assertEquals($expectedResult, $result);
165+
}
100166
}

0 commit comments

Comments
 (0)