mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-28 05:33:30 +00:00
5988584736
Co-authored-by: rector-bot <tomas@getrector.org>
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Name;
|
|
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
|
use PHPStan\Type\FloatType;
|
|
use PHPStan\Type\Type;
|
|
use PHPStan\Type\VerbosityLevel;
|
|
use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode;
|
|
use Rector\Core\Php\PhpVersionProvider;
|
|
use Rector\Core\ValueObject\PhpVersionFeature;
|
|
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
|
|
|
final class FloatTypeMapper implements TypeMapperInterface
|
|
{
|
|
/**
|
|
* @var PhpVersionProvider
|
|
*/
|
|
private $phpVersionProvider;
|
|
|
|
public function __construct(PhpVersionProvider $phpVersionProvider)
|
|
{
|
|
$this->phpVersionProvider = $phpVersionProvider;
|
|
}
|
|
|
|
public function getNodeClass(): string
|
|
{
|
|
return FloatType::class;
|
|
}
|
|
|
|
/**
|
|
* @param FloatType $type
|
|
*/
|
|
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
|
|
{
|
|
return new AttributeAwareIdentifierTypeNode('float');
|
|
}
|
|
|
|
/**
|
|
* @param FloatType $type
|
|
*/
|
|
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
|
|
{
|
|
if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) {
|
|
return null;
|
|
}
|
|
|
|
return new Name('float');
|
|
}
|
|
|
|
public function mapToDocString(Type $type, ?Type $parentType = null): string
|
|
{
|
|
return $type->describe(VerbosityLevel::typeOnly());
|
|
}
|
|
}
|