Skip to content

Commit

Permalink
Renamed Fn to TFn to allow for PHP 7.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius authored and muglug committed Jun 3, 2019
1 parent fc0f625 commit 624c7bc
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function analyze(

/** @var PhpParser\Node\Expr\Closure $this->function */
$this->function->inferredType = new Type\Union([
new Type\Atomic\Fn(
new Type\Atomic\TFn(
'Closure',
$storage->params,
$closure_return_type
Expand Down Expand Up @@ -858,7 +858,7 @@ function (FunctionLikeParameter $p) {
)
) {
if ($this->function->inferredType) {
/** @var Type\Atomic\Fn */
/** @var Type\Atomic\TFn */
$closure_atomic = $this->function->inferredType->getTypes()['Closure'];
$closure_atomic->return_type = $closure_return_type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function analyze(
$has_valid_function_call_type = false;

foreach ($stmt->name->inferredType->getTypes() as $var_type_part) {
if ($var_type_part instanceof Type\Atomic\Fn || $var_type_part instanceof Type\Atomic\TCallable) {
if ($var_type_part instanceof Type\Atomic\TFn || $var_type_part instanceof Type\Atomic\TCallable) {
$function_params = $var_type_part->params;

if (isset($stmt->inferredType) && $var_type_part->return_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ function (PhpParser\Node\Param $closure_param) : bool {

foreach ($replaced_type->getTypes() as $replaced_type_part) {
if ($replaced_type_part instanceof Type\Atomic\TCallable
|| $replaced_type_part instanceof Type\Atomic\Fn
|| $replaced_type_part instanceof Type\Atomic\TFn
) {
foreach ($closure_storage->params as $closure_param_offset => $param_storage) {
if (isset($replaced_type_part->params[$closure_param_offset]->type)
Expand Down Expand Up @@ -1859,7 +1859,7 @@ private static function checkArrayFunctionClosureType(
) {
$codebase = $statements_analyzer->getCodebase();

if (!$closure_type instanceof Type\Atomic\Fn) {
if (!$closure_type instanceof Type\Atomic\TFn) {
if (!$closure_arg->value instanceof PhpParser\Node\Scalar\String_
&& !$closure_arg->value instanceof PhpParser\Node\Expr\Array_
&& !$closure_arg->value instanceof PhpParser\Node\Expr\BinaryOp\Concat
Expand Down Expand Up @@ -1913,7 +1913,7 @@ private static function checkArrayFunctionClosureType(
continue;
}

$closure_types[] = new Type\Atomic\Fn(
$closure_types[] = new Type\Atomic\TFn(
'Closure',
$method_storage->params,
$method_storage->return_type ?: Type::getMixed()
Expand Down Expand Up @@ -1958,21 +1958,21 @@ private static function checkArrayFunctionClosureType(

if ($passing_callmap_params_options) {
foreach ($passing_callmap_params_options as $passing_callmap_params_option) {
$closure_types[] = new Type\Atomic\Fn(
$closure_types[] = new Type\Atomic\TFn(
'Closure',
$passing_callmap_params_option,
$function_storage->return_type ?: Type::getMixed()
);
}
} else {
$closure_types[] = new Type\Atomic\Fn(
$closure_types[] = new Type\Atomic\TFn(
'Closure',
$callmap_params_options[0],
$function_storage->return_type ?: Type::getMixed()
);
}
} else {
$closure_types[] = new Type\Atomic\Fn(
$closure_types[] = new Type\Atomic\TFn(
'Closure',
$function_storage->params,
$function_storage->return_type ?: Type::getMixed()
Expand Down Expand Up @@ -2014,7 +2014,7 @@ private static function checkArrayFunctionClosureType(
private static function checkArrayFunctionClosureTypeArgs(
StatementsAnalyzer $statements_analyzer,
$method_id,
Type\Atomic\Fn $closure_type,
Type\Atomic\TFn $closure_type,
PhpParser\Node\Arg $closure_arg,
$min_closure_param_count,
$max_closure_param_count,
Expand Down
12 changes: 6 additions & 6 deletions src/Psalm/Internal/Analyzer/TypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public static function isAtomicContainedBy(
return true;
}

if ($container_type_part instanceof TCallable && $input_type_part instanceof Type\Atomic\Fn) {
if ($container_type_part instanceof TCallable && $input_type_part instanceof Type\Atomic\TFn) {
$all_types_contain = true;

if (self::compareCallable(
Expand Down Expand Up @@ -1194,7 +1194,7 @@ public static function isAtomicContainedBy(
}
}

if ($container_type_part instanceof Type\Atomic\Fn && $input_type_part instanceof TCallable) {
if ($container_type_part instanceof Type\Atomic\TFn && $input_type_part instanceof TCallable) {
$type_coerced = true;

return false;
Expand Down Expand Up @@ -1707,8 +1707,8 @@ private static function isMatchingTypeContainedBy(
}
}

if ($container_type_part instanceof Type\Atomic\Fn) {
if (!$input_type_part instanceof Type\Atomic\Fn) {
if ($container_type_part instanceof Type\Atomic\TFn) {
if (!$input_type_part instanceof Type\Atomic\TFn) {
$type_coerced = true;
$type_coerced_from_mixed = true;

Expand Down Expand Up @@ -1838,8 +1838,8 @@ function ($carry, Type\Union $item) {
}

/**
* @param TCallable|Type\Atomic\Fn $input_type_part
* @param TCallable|Type\Atomic\Fn $container_type_part
* @param TCallable|Type\Atomic\TFn $input_type_part
* @param TCallable|Type\Atomic\TFn $container_type_part
* @param bool &$type_coerced
* @param bool &$type_coerced_from_mixed
* @param bool $has_scalar_match
Expand Down
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Codebase/Methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static function localizeParamType(
}

if ($atomic_type instanceof Type\Atomic\TCallable
|| $atomic_type instanceof Type\Atomic\Fn
|| $atomic_type instanceof Type\Atomic\TFn
) {
if ($atomic_type->params) {
foreach ($atomic_type->params as $param) {
Expand Down Expand Up @@ -571,11 +571,11 @@ public function getMethodReturnType($method_id, &$self_class, array $args = null
) {
foreach ($args[0]->value->inferredType->getTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TCallable
|| $atomic_type instanceof Type\Atomic\Fn
|| $atomic_type instanceof Type\Atomic\TFn
) {
$callable_type = clone $atomic_type;

return new Type\Union([new Type\Atomic\Fn(
return new Type\Union([new Type\Atomic\TFn(
'Closure',
$callable_type->params,
$callable_type->return_type
Expand All @@ -587,7 +587,7 @@ public function getMethodReturnType($method_id, &$self_class, array $args = null
) {
$invokable_storage = $this->getStorage($atomic_type->value . '::__invoke');

return new Type\Union([new Type\Atomic\Fn(
return new Type\Union([new Type\Atomic\TFn(
'Closure',
$invokable_storage->params,
$invokable_storage->return_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function getFunctionReturnType(
if ($function_call_arg->value instanceof PhpParser\Node\Expr\Closure
&& isset($function_call_arg->value->inferredType)
&& ($closure_atomic_type = $function_call_arg->value->inferredType->getTypes()['Closure'])
&& $closure_atomic_type instanceof Type\Atomic\Fn
&& $closure_atomic_type instanceof Type\Atomic\TFn
) {
$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function getFunctionReturnType(
&& ($closure_atomic_type = isset($first_arg_atomic_types['Closure'])
? $first_arg_atomic_types['Closure']
: null)
&& $closure_atomic_type instanceof Type\Atomic\Fn
&& $closure_atomic_type instanceof Type\Atomic\TFn
) {
$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function getFunctionReturnType(
&& ($closure_atomic_type = isset($first_arg_atomic_types['Closure'])
? $first_arg_atomic_types['Closure']
: null)
&& $closure_atomic_type instanceof Type\Atomic\Fn
&& $closure_atomic_type instanceof Type\Atomic\TFn
) {
$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();

Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Type/TypeCombination.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static function combineTypes(
}

if (isset($combination->named_object_types['Closure'])
&& $combination->named_object_types['Closure'] instanceof Type\Atomic\Fn
&& $combination->named_object_types['Closure'] instanceof Type\Atomic\TFn
&& $combination->closure_params
) {
$combination->named_object_types['Closure']->params = $combination->closure_params;
Expand Down Expand Up @@ -607,7 +607,7 @@ private static function scrapeTypeProperties(
);
}

if ($type instanceof Type\Atomic\Fn
if ($type instanceof Type\Atomic\TFn
|| $type instanceof Type\Atomic\TCallable
) {
if ($type->params) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function (ParseTree $child_tree) use ($template_type_map) {
if ($parse_tree instanceof ParseTree\CallableWithReturnTypeTree) {
$callable_type = self::getTypeFromTree($parse_tree->children[0], null, $template_type_map);

if (!$callable_type instanceof TCallable && !$callable_type instanceof Type\Atomic\Fn) {
if (!$callable_type instanceof TCallable && !$callable_type instanceof Type\Atomic\TFn) {
throw new \InvalidArgumentException('Parsing callable tree node should return TCallable');
}

Expand Down Expand Up @@ -524,7 +524,7 @@ function (ParseTree $child_tree) use ($template_type_map) {
);

if (in_array(strtolower($parse_tree->value), ['closure', '\closure'], true)) {
return new Type\Atomic\Fn('Closure', $params);
return new Type\Atomic\TFn('Closure', $params);
}

return new TCallable($parse_tree->value, $params);
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type/Atomic.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public function check(
}
}

if ($this instanceof Type\Atomic\Fn
if ($this instanceof Type\Atomic\TFn
|| $this instanceof Type\Atomic\TCallable
) {
if ($this->params) {
Expand Down Expand Up @@ -684,7 +684,7 @@ public function queueClassLikesForScanning(
}
}

if ($this instanceof Type\Atomic\Fn
if ($this instanceof Type\Atomic\TFn
|| $this instanceof Type\Atomic\TCallable
) {
if ($this->params) {
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Type/Atomic/CallableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function replaceTemplateTypesWithStandins(
foreach ($this->params as $offset => $param) {
$input_param_type = null;

if (($input_type instanceof Atomic\Fn || $input_type instanceof Atomic\TCallable)
if (($input_type instanceof Atomic\TFn || $input_type instanceof Atomic\TCallable)
&& isset($input_type->params[$offset])
) {
$input_param_type = $input_type->params[$offset]->type;
Expand All @@ -211,7 +211,7 @@ public function replaceTemplateTypesWithStandins(
}
}

if (($input_type instanceof Atomic\TCallable || $input_type instanceof Atomic\Fn)
if (($input_type instanceof Atomic\TCallable || $input_type instanceof Atomic\TFn)
&& $this->return_type
&& $input_type->return_type
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* Represents a closure where we know the return type and params
*/
class Fn extends TNamedObject
class TFn extends TNamedObject
{
use CallableTrait;

Expand Down

0 comments on commit 624c7bc

Please sign in to comment.