decouple CallableTypeMapper, ClosureTypeMapper

This commit is contained in:
TomasVotruba 2020-01-14 22:06:21 +01:00
parent 35911cb872
commit 5aac9a3d69
3 changed files with 82 additions and 8 deletions

View File

@ -122,14 +122,6 @@ final class PHPStanStaticTypeMapper
return null;
}
if ($phpStanType instanceof CallableType || $phpStanType instanceof ClosureType) {
if ($kind === 'property') {
return null;
}
return new Identifier('callable');
}
if ($phpStanType instanceof TypeWithClassName) {
$lowerCasedClassName = strtolower($phpStanType->getClassName());
if ($lowerCasedClassName === 'callable') {

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\CallableType;
use PHPStan\Type\Type;
use Rector\Exception\NotImplementedException;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
final class CallableTypeMapper implements TypeMapperInterface
{
public function getNodeClass(): string
{
return CallableType::class;
}
/**
* @param CallableType $type
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
throw new NotImplementedException();
}
/**
* @param CallableType $type
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
if ($kind === 'property') {
return null;
}
return new Identifier('callable');
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Type;
use Rector\Exception\NotImplementedException;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
final class ClosureTypeMapper implements TypeMapperInterface
{
public function getNodeClass(): string
{
return ClosureType::class;
}
/**
* @param ClosureType $type
*/
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
{
throw new NotImplementedException();
}
/**
* @param ClosureType $type
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
if ($kind === 'property') {
return null;
}
return new Identifier('callable');
}
}