Skip to content

Commit

Permalink
Restore src/Analyser/TypeSpecifier.php
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 18, 2022
1 parent 653b3bf commit e972230
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Analyser/TypeSpecifier.php
Expand Up @@ -31,6 +31,8 @@
use PHPStan\Type\Accessory\HasOffsetType;
use PHPStan\Type\Accessory\HasPropertyType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\ConditionalTypeForParameter;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\Constant\ConstantBooleanType;
Expand All @@ -54,9 +56,11 @@
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\ResourceType;
use PHPStan\Type\StaticMethodTypeSpecifyingExtension;
use PHPStan\Type\StaticType;
use PHPStan\Type\StaticTypeFactory;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeTraverser;
Expand Down Expand Up @@ -1076,7 +1080,31 @@ private function specifyTypesForConstantStringBinaryExpression(
&& strtolower($exprNode->name->toString()) === 'gettype'
&& isset($exprNode->getArgs()[0])
) {
$type = GetTypeHelper::typeFromString($constantType->getValue());
$type = null;
if ($constantType->getValue() === 'string') {
$type = new StringType();
}
if ($constantType->getValue() === 'array') {
$type = new ArrayType(new MixedType(), new MixedType());
}
if ($constantType->getValue() === 'boolean') {
$type = new BooleanType();
}
if ($constantType->getValue() === 'resource' || $constantType->getValue() === 'resource (closed)') {
$type = new ResourceType();
}
if ($constantType->getValue() === 'integer') {
$type = new IntegerType();
}
if ($constantType->getValue() === 'double') {
$type = new FloatType();
}
if ($constantType->getValue() === 'NULL') {
$type = new NullType();
}
if ($constantType->getValue() === 'object') {
$type = new ObjectWithoutClassType();
}

if ($type !== null) {
return $this->create($exprNode->getArgs()[0]->value, $type, $context, false, $scope, $rootExpr);
Expand Down

0 comments on commit e972230

Please sign in to comment.