This commit is contained in:
TomasVotruba 2020-01-28 10:08:08 +01:00
parent 3b676ad57c
commit b11261ff69
2 changed files with 22 additions and 17 deletions

View File

@ -200,7 +200,7 @@ final class NodeTypeResolver
if ($nodeType instanceof UnionType) {
foreach ($nodeType->getTypes() as $singleType) {
if (! $singleType instanceof StringType) {
if ($singleType->isSuperTypeOf(new StringType())->no()) {
return false;
}
}
@ -227,21 +227,12 @@ final class NodeTypeResolver
public function isCountableType(Node $node): bool
{
$nodeType = $this->getStaticType($node);
$nodeType = $this->pregMatchTypeCorrector->correct($node, $nodeType);
if ($nodeType instanceof ObjectType) {
if (is_a($nodeType->getClassName(), Countable::class, true)) {
return true;
}
// @see https://github.com/rectorphp/rector/issues/2028
if (is_a($nodeType->getClassName(), 'SimpleXMLElement', true)) {
if ($this->isCountableObjectType($nodeType)) {
return true;
}
return is_a($nodeType->getClassName(), 'ResourceBundle', true);
}
return $this->isArrayType($node);
}
@ -334,10 +325,6 @@ final class NodeTypeResolver
return new ArrayType(new MixedType(), new MixedType());
}
if ($this->isStringOrUnionStringOnlyType($expr)) {
return new StringType();
}
return $this->getStaticType($expr);
}
@ -648,4 +635,22 @@ final class NodeTypeResolver
return $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($typeNode, new Nop());
}
private function isCountableObjectType(Type $type): bool
{
if (! $type instanceof ObjectType) {
return false;
}
if (is_a($type->getClassName(), Countable::class, true)) {
return true;
}
// @see https://github.com/rectorphp/rector/issues/2028
if (is_a($type->getClassName(), 'SimpleXMLElement', true)) {
return true;
}
return is_a($type->getClassName(), 'ResourceBundle', true);
}
}

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Rector\NodeTypeResolver\PerNodeTypeResolver;
use PhpParser\Node\Scalar;
use PhpParser\Node;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\MagicConst;