Map iterable in ScalarStringToTypeMapper (#4482)

* Map iterable in ScalarStringToTypeMapper

* Add test
This commit is contained in:
Raffael Comi 2020-10-28 21:42:17 +01:00 committed by GitHub
parent 35502016a6
commit 7bd20258bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Rector\NodeTypeResolver\Tests\StaticTypeMapper;
use Iterator;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
@ -74,4 +76,18 @@ final class StaticTypeMapperTest extends AbstractKernelTestCase
$phpStanDocTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($mixedType);
$this->assertInstanceOf(IdentifierTypeNode::class, $phpStanDocTypeNode);
}
/**
* @dataProvider provideDataForMapPhpParserNodePHPStanType()
*/
public function testMapPhpParserNodePHPStanType(Node $node, string $expectedType): void
{
$phpStanType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node);
$this->assertInstanceOf($expectedType, $phpStanType);
}
public function provideDataForMapPhpParserNodePHPStanType(): Iterator
{
yield [new Identifier('iterable'), IterableType::class];
}
}

View File

@ -10,6 +10,7 @@ use PHPStan\Type\BooleanType;
use PHPStan\Type\CallableType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectWithoutClassType;
@ -51,6 +52,10 @@ final class ScalarStringToTypeMapper
return new ArrayType(new MixedType(), new MixedType());
}
if ($loweredScalarName === 'iterable') {
return new IterableType(new MixedType(), new MixedType());
}
if ($loweredScalarName === 'mixed') {
return new MixedType(true);
}