Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Jan 16, 2022
1 parent 9bc74bd commit 62a0923
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php
Expand Up @@ -65,6 +65,7 @@ public static function analyze(
}

$valid_int_type = null;
$type_parent_nodes = null;
$maybe_type = $statements_analyzer->node_data->getType($stmt->expr);

if ($maybe_type) {
Expand All @@ -73,12 +74,8 @@ public static function analyze(
if (!$maybe_type->from_calculation) {
self::handleRedundantCast($maybe_type, $statements_analyzer, $stmt);
}

if ($maybe_type->isSingleStringLiteral()) {
$valid_int_type = new Union([
new TLiteralInt((int)$maybe_type->getSingleStringLiteral()->value),
]);
}
} elseif ($maybe_type->isSingleStringLiteral()) {
$valid_int_type = Type::getInt(false, (int)$maybe_type->getSingleStringLiteral()->value);
}

if (count($maybe_type->getAtomicTypes()) === 1
Expand All @@ -88,13 +85,15 @@ public static function analyze(
new TLiteralInt(1),
]);
}

if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph) {
$type_parent_nodes = $maybe_type->parent_nodes;
}
}

$type = $valid_int_type ?? Type::getInt();

if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph
) {
$type->parent_nodes = $maybe_type->parent_nodes ?? [];
if ($type_parent_nodes !== null) {
$type->parent_nodes = $type_parent_nodes;
}

$statements_analyzer->node_data->setType($stmt, $type);
Expand Down

0 comments on commit 62a0923

Please sign in to comment.