mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-12 06:02:23 +00:00
7e7a2f067a
476cfb00cb
disable fallback for now
56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\NodeTypeResolver\NodeTypeResolver;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Scalar;
|
|
use PhpParser\Node\Scalar\DNumber;
|
|
use PhpParser\Node\Scalar\Encapsed;
|
|
use PhpParser\Node\Scalar\EncapsedStringPart;
|
|
use PhpParser\Node\Scalar\LNumber;
|
|
use PhpParser\Node\Scalar\MagicConst;
|
|
use PhpParser\Node\Scalar\String_;
|
|
use PHPStan\Type\Constant\ConstantFloatType;
|
|
use PHPStan\Type\Constant\ConstantIntegerType;
|
|
use PHPStan\Type\Constant\ConstantStringType;
|
|
use PHPStan\Type\StringType;
|
|
use PHPStan\Type\Type;
|
|
use Rector\Exception\NotImplementedYetException;
|
|
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
|
/**
|
|
* @implements NodeTypeResolverInterface<Scalar>
|
|
*/
|
|
final class ScalarTypeResolver implements NodeTypeResolverInterface
|
|
{
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeClasses() : array
|
|
{
|
|
return [Scalar::class];
|
|
}
|
|
public function resolve(Node $node) : Type
|
|
{
|
|
if ($node instanceof DNumber) {
|
|
return new ConstantFloatType((float) $node->value);
|
|
}
|
|
if ($node instanceof String_) {
|
|
return new ConstantStringType((string) $node->value);
|
|
}
|
|
if ($node instanceof LNumber) {
|
|
return new ConstantIntegerType((int) $node->value);
|
|
}
|
|
if ($node instanceof MagicConst) {
|
|
return new ConstantStringType($node->getName());
|
|
}
|
|
if ($node instanceof Encapsed) {
|
|
return new StringType();
|
|
}
|
|
if ($node instanceof EncapsedStringPart) {
|
|
return new ConstantStringType($node->value);
|
|
}
|
|
throw new NotImplementedYetException();
|
|
}
|
|
}
|