mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-28 13:43:31 +00:00
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Name;
|
|
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
|
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
|
use PHPStan\Type\StringType;
|
|
use PHPStan\Type\Type;
|
|
use Rector\Core\Php\PhpVersionProvider;
|
|
use Rector\Core\ValueObject\PhpVersionFeature;
|
|
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
|
|
|
final class StringTypeMapper implements TypeMapperInterface
|
|
{
|
|
/**
|
|
* @var PhpVersionProvider
|
|
*/
|
|
private $phpVersionProvider;
|
|
|
|
public function __construct(PhpVersionProvider $phpVersionProvider)
|
|
{
|
|
$this->phpVersionProvider = $phpVersionProvider;
|
|
}
|
|
|
|
/**
|
|
* @return class-string<Type>
|
|
*/
|
|
public function getNodeClass(): string
|
|
{
|
|
return StringType::class;
|
|
}
|
|
|
|
/**
|
|
* @param StringType $type
|
|
*/
|
|
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
|
|
{
|
|
return new IdentifierTypeNode('string');
|
|
}
|
|
|
|
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
|
|
{
|
|
if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) {
|
|
return null;
|
|
}
|
|
|
|
return new Name('string');
|
|
}
|
|
}
|