Skip to content

Commit

Permalink
Remove mistakenly-duplicated code for get_* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 25, 2021
1 parent 924f6b6 commit b2c3583
Showing 1 changed file with 0 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,95 +416,6 @@ private static function handleDependentTypeFunction(
if ($first_arg) {
$var = $first_arg->value;

if ($var instanceof PhpParser\Node\Expr\Variable
&& is_string($var->name)
) {
$var_id = '$' . $var->name;

if (isset($context->vars_in_scope[$var_id])) {
if ($function_id === 'get_class') {
$atomic_type = new Type\Atomic\TDependentGetClass(
$var_id,
$context->vars_in_scope[$var_id]->hasMixed()
? Type::getObject()
: $context->vars_in_scope[$var_id]
);
} elseif ($function_id === 'gettype') {
$atomic_type = new Type\Atomic\TDependentGetType($var_id);
} else {
$atomic_type = new Type\Atomic\TDependentGetDebugType($var_id);
}

$statements_analyzer->node_data->setType($real_stmt, new Type\Union([$atomic_type]));
}
} elseif (($var_type = $statements_analyzer->node_data->getType($var))
&& ($function_id === 'get_class'
|| $function_id === 'get_debug_type'
)
) {
$class_string_types = [];

foreach ($var_type->getAtomicTypes() as $class_type) {
if ($class_type instanceof Type\Atomic\TNamedObject) {
$class_string_types[] = new Type\Atomic\TClassString($class_type->value, clone $class_type);
} elseif ($class_type instanceof Type\Atomic\TTemplateParam
&& $class_type->as->isSingle()
) {
$as_atomic_type = \array_values($class_type->as->getAtomicTypes())[0];

if ($as_atomic_type instanceof Type\Atomic\TObject) {
$class_string_types[] = new Type\Atomic\TTemplateParamClass(
$class_type->param_name,
'object',
null,
$class_type->defining_class
);
} elseif ($as_atomic_type instanceof TNamedObject) {
$class_string_types[] = new Type\Atomic\TTemplateParamClass(
$class_type->param_name,
$as_atomic_type->value,
$as_atomic_type,
$class_type->defining_class
);
}
} elseif ($function_id === 'get_class') {
$class_string_types[] = new Type\Atomic\TClassString();
} {
if ($class_type instanceof Type\Atomic\TInt) {
$class_string_types[] = new Type\Atomic\TLiteralString('int');
} elseif ($class_type instanceof Type\Atomic\TString) {
$class_string_types[] = new Type\Atomic\TLiteralString('string');
} elseif ($class_type instanceof Type\Atomic\TFloat) {
$class_string_types[] = new Type\Atomic\TLiteralString('float');
} elseif ($class_type instanceof Type\Atomic\TBool) {
$class_string_types[] = new Type\Atomic\TLiteralString('bool');
} elseif ($class_type instanceof Type\Atomic\TClosedResource) {
$class_string_types[] = new Type\Atomic\TLiteralString('resource (closed)');
} elseif ($class_type instanceof Type\Atomic\TNull) {
$class_string_types[] = new Type\Atomic\TLiteralString('null');
} else {
$class_string_types[] = new Type\Atomic\TString();
}
}
}

$statements_analyzer->node_data->setType($real_stmt, new Type\Union($class_string_types));
}
} elseif ($function_id === 'get_class'
&& ($get_class_name = $statements_analyzer->getFQCLN())
) {
$statements_analyzer->node_data->setType(
$real_stmt,
new Type\Union([
new Type\Atomic\TClassString(
$get_class_name,
new Type\Atomic\TNamedObject($get_class_name)
)
])
);
}if ($first_arg) {
$var = $first_arg->value;

if ($var instanceof PhpParser\Node\Expr\Variable
&& is_string($var->name)
) {
Expand Down

0 comments on commit b2c3583

Please sign in to comment.