|
12 | 12 | use PhpParser\Node\Stmt\Class_; |
13 | 13 | use PhpParser\Node\Stmt\Property; |
14 | 14 | use PHPStan\Reflection\ClassReflection; |
| 15 | +use PHPStan\Type\FloatType; |
15 | 16 | use PHPStan\Type\MixedType; |
16 | 17 | use PHPStan\Type\ObjectType; |
17 | 18 | use PHPStan\Type\StringType; |
18 | | -use PHPStan\Type\Type; |
19 | 19 | use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; |
20 | 20 | use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; |
21 | 21 | use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; |
@@ -122,14 +122,14 @@ public function provideMinPhpVersion(): int |
122 | 122 | */ |
123 | 123 | public function refactor(Node $node): ?Node |
124 | 124 | { |
125 | | - $hasChanged = \false; |
126 | 125 | if (!$this->hasAtLeastOneUntypedPropertyUsingJmsAttribute($node)) { |
127 | 126 | return null; |
128 | 127 | } |
129 | 128 | $classReflection = $this->reflectionResolver->resolveClassReflection($node); |
130 | 129 | if (!$classReflection instanceof ClassReflection) { |
131 | 130 | return null; |
132 | 131 | } |
| 132 | + $hasChanged = \false; |
133 | 133 | foreach ($node->getProperties() as $property) { |
134 | 134 | if ($this->shouldSkipProperty($property, $classReflection)) { |
135 | 135 | continue; |
@@ -187,12 +187,18 @@ private function createTypeNode(string $typeValue, Property $property): ?Node |
187 | 187 | { |
188 | 188 | if ($typeValue === 'float') { |
189 | 189 | $propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property); |
190 | | - if ($propertyPhpDocInfo instanceof PhpDocInfo) { |
191 | | - // fallback to string, as most likely string representation of float |
192 | | - if ($propertyPhpDocInfo->getVarType() instanceof StringType) { |
193 | | - $this->varTagRemover->removeVarTag($property); |
194 | | - return new Identifier('string'); |
195 | | - } |
| 190 | + // fallback to string, as most likely string representation of float |
| 191 | + if ($propertyPhpDocInfo instanceof PhpDocInfo && $propertyPhpDocInfo->getVarType() instanceof StringType) { |
| 192 | + $this->varTagRemover->removeVarTag($property); |
| 193 | + return new Identifier('string'); |
| 194 | + } |
| 195 | + } |
| 196 | + if ($typeValue === 'string') { |
| 197 | + $propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property); |
| 198 | + // fallback to string, as most likely string representation of float |
| 199 | + if ($propertyPhpDocInfo instanceof PhpDocInfo && $propertyPhpDocInfo->getVarType() instanceof FloatType) { |
| 200 | + $this->varTagRemover->removeVarTag($property); |
| 201 | + return new Identifier('float'); |
196 | 202 | } |
197 | 203 | } |
198 | 204 | $type = $this->scalarStringToTypeMapper->mapScalarStringToType($typeValue); |
|
0 commit comments