mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 20:22:24 +00:00
[TypeDeclaratoin] Add AccessoryLiteralStringType to static type mapper (#1558)
This commit is contained in:
parent
6c8a69e956
commit
89c3483001
|
@ -8,6 +8,7 @@ use PhpParser\Node\ComplexType;
|
|||
use PhpParser\Node\Name;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
|
||||
use PHPStan\Type\Accessory\AccessoryNumericStringType;
|
||||
use PHPStan\Type\Accessory\HasMethodType;
|
||||
use PHPStan\Type\Type;
|
||||
|
@ -43,6 +44,10 @@ final class PHPStanStaticTypeMapper
|
|||
return new IdentifierTypeNode('object');
|
||||
}
|
||||
|
||||
if ($type instanceof AccessoryLiteralStringType) {
|
||||
return new IdentifierTypeNode('string');
|
||||
}
|
||||
|
||||
throw new NotImplementedYetException(__METHOD__ . ' for ' . $type::class);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
|
||||
|
||||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source\ExternalList;
|
||||
|
||||
final class ForeachLiteral
|
||||
{
|
||||
public function run(): array
|
||||
{
|
||||
$map = [];
|
||||
foreach (ExternalList::VALUES as $externalValue) {
|
||||
$map[$externalValue] = 100;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
}
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
|
||||
|
||||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source\ExternalList;
|
||||
|
||||
final class ForeachLiteral
|
||||
{
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function run(): array
|
||||
{
|
||||
$map = [];
|
||||
foreach (ExternalList::VALUES as $externalValue) {
|
||||
$map[$externalValue] = 100;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Source;
|
||||
|
||||
final class ExternalList
|
||||
{
|
||||
public const FIRST = 'first';
|
||||
|
||||
public const SECOND = 'second';
|
||||
|
||||
public const VALUES = [self::FIRST, self::SECOND];
|
||||
}
|
Loading…
Reference in New Issue
Block a user