1313use PhpParser \Node \Stmt \Class_ ;
1414use PhpParser \Node \Stmt \Property ;
1515use PHPStan \Reflection \ClassReflection ;
16+ use PHPStan \Type \FloatType ;
1617use PHPStan \Type \MixedType ;
1718use PHPStan \Type \ObjectType ;
1819use PHPStan \Type \StringType ;
19- use PHPStan \Type \Type ;
2020use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfo ;
2121use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
2222use Rector \DeadCode \PhpDoc \TagRemover \VarTagRemover ;
@@ -97,8 +97,6 @@ public function provideMinPhpVersion(): int
9797 */
9898 public function refactor (Node $ node ): ?Node
9999 {
100- $ hasChanged = false ;
101-
102100 if (! $ this ->hasAtLeastOneUntypedPropertyUsingJmsAttribute ($ node )) {
103101 return null ;
104102 }
@@ -108,6 +106,8 @@ public function refactor(Node $node): ?Node
108106 return null ;
109107 }
110108
109+ $ hasChanged = false ;
110+
111111 foreach ($ node ->getProperties () as $ property ) {
112112 if ($ this ->shouldSkipProperty ($ property , $ classReflection )) {
113113 continue ;
@@ -180,13 +180,19 @@ private function createTypeNode(string $typeValue, Property $property): ?Node
180180 {
181181 if ($ typeValue === 'float ' ) {
182182 $ propertyPhpDocInfo = $ this ->phpDocInfoFactory ->createFromNode ($ property );
183- if ($ propertyPhpDocInfo instanceof PhpDocInfo) {
184- // fallback to string, as most likely string representation of float
185- if ($ propertyPhpDocInfo ->getVarType () instanceof StringType) {
186- $ this ->varTagRemover ->removeVarTag ($ property );
183+ // fallback to string, as most likely string representation of float
184+ if ($ propertyPhpDocInfo instanceof PhpDocInfo && $ propertyPhpDocInfo ->getVarType () instanceof StringType) {
185+ $ this ->varTagRemover ->removeVarTag ($ property );
186+ return new Identifier ('string ' );
187+ }
188+ }
187189
188- return new Identifier ('string ' );
189- }
190+ if ($ typeValue === 'string ' ) {
191+ $ propertyPhpDocInfo = $ this ->phpDocInfoFactory ->createFromNode ($ property );
192+ // fallback to string, as most likely string representation of float
193+ if ($ propertyPhpDocInfo instanceof PhpDocInfo && $ propertyPhpDocInfo ->getVarType () instanceof FloatType) {
194+ $ this ->varTagRemover ->removeVarTag ($ property );
195+ return new Identifier ('float ' );
190196 }
191197 }
192198
0 commit comments