File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed
rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture
rules/CodeQuality/Rector/MethodCall Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \ScalarArgumentToExpectedParamTypeRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \ScalarArgumentToExpectedParamTypeRector \Source \NullableSetter ;
7+
8+ final class PassFloatToNullableString extends TestCase
9+ {
10+ public function test ()
11+ {
12+ $ nullableSetter = new NullableSetter ();
13+ $ nullableSetter ->setMaybe (123.456 );
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \ScalarArgumentToExpectedParamTypeRector \Fixture ;
22+
23+ use PHPUnit \Framework \TestCase ;
24+ use Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \ScalarArgumentToExpectedParamTypeRector \Source \NullableSetter ;
25+
26+ final class PassFloatToNullableString extends TestCase
27+ {
28+ public function test ()
29+ {
30+ $ nullableSetter = new NullableSetter ();
31+ $ nullableSetter ->setMaybe ('123.456 ' );
32+ }
33+ }
34+
35+ ?>
Original file line number Diff line number Diff line change 88use PhpParser \Node \Expr \MethodCall ;
99use PhpParser \Node \Expr \StaticCall ;
1010use PhpParser \Node \Scalar ;
11+ use PhpParser \Node \Scalar \Float_ ;
1112use PhpParser \Node \Scalar \Int_ ;
1213use PhpParser \Node \Scalar \String_ ;
1314use PHPStan \Type \IntegerType ;
@@ -114,9 +115,16 @@ public function refactor(Node $node): ?Node
114115 // remove null
115116 $ knownParameterType = TypeCombinator::removeNull ($ knownParameterType );
116117
117- if ($ knownParameterType instanceof StringType && $ arg ->value instanceof Int_) {
118- $ arg ->value = new String_ ((string ) $ arg ->value ->value );
119- $ hasChanged = true ;
118+ if ($ knownParameterType instanceof StringType) {
119+ if ($ arg ->value instanceof Int_) {
120+ $ arg ->value = new String_ ((string ) $ arg ->value ->value );
121+ $ hasChanged = true ;
122+ }
123+
124+ if ($ arg ->value instanceof Float_) {
125+ $ arg ->value = new String_ ((string ) $ arg ->value ->value );
126+ $ hasChanged = true ;
127+ }
120128 }
121129
122130 if ($ knownParameterType instanceof IntegerType && $ arg ->value instanceof String_) {
@@ -159,6 +167,10 @@ private function hasStringOrNumberArguments(StaticCall|MethodCall $call): bool
159167 if ($ arg ->value instanceof String_) {
160168 return true ;
161169 }
170+
171+ if ($ arg ->value instanceof Float_) {
172+ return true ;
173+ }
162174 }
163175
164176 return false ;
You can’t perform that action at this time.
0 commit comments