1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 19:07:00 +01:00
psalm/src/Psalm/Internal/Analyzer/Statements/Expression/BooleanNotAnalyzer.php
Matt Brown 14efde286f 4.x - refactor unused variable detection
This turns unused variable detection into an explicit control-flow problem, where before we had a more simplistic mark-and-sweep algorithm
2020-09-30 12:28:13 -04:00

37 lines
998 B
PHP

<?php
namespace Psalm\Internal\Analyzer\Statements\Expression;
use PhpParser;
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
use Psalm\Internal\Analyzer\StatementsAnalyzer;
use Psalm\Context;
use Psalm\Type;
class BooleanNotAnalyzer
{
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\BooleanNot $stmt,
Context $context
) : bool {
$stmt_type = Type::getBool();
$statements_analyzer->node_data->setType($stmt, $stmt_type);
$inside_negation = $context->inside_negation;
$context->inside_negation = !$inside_negation;
$result = ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context);
$context->inside_negation = $inside_negation;
$expr_type = $statements_analyzer->node_data->getType($stmt->expr);
if ($expr_type) {
$stmt_type->parent_nodes = $expr_type->parent_nodes;
}
return $result;
}
}