2020-05-18 21:13:27 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Internal\Analyzer\Statements\Expression;
|
|
|
|
|
|
|
|
use PhpParser;
|
2021-06-08 04:55:21 +02:00
|
|
|
use Psalm\Context;
|
2020-05-18 21:13:27 +02:00
|
|
|
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
|
|
|
use Psalm\Type;
|
|
|
|
|
|
|
|
class BooleanNotAnalyzer
|
|
|
|
{
|
|
|
|
public static function analyze(
|
|
|
|
StatementsAnalyzer $statements_analyzer,
|
|
|
|
PhpParser\Node\Expr\BooleanNot $stmt,
|
|
|
|
Context $context
|
|
|
|
) : bool {
|
2021-09-22 16:49:16 +02:00
|
|
|
|
2020-05-18 21:13:27 +02:00
|
|
|
|
|
|
|
$inside_negation = $context->inside_negation;
|
|
|
|
|
|
|
|
$context->inside_negation = !$inside_negation;
|
|
|
|
|
|
|
|
$result = ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context);
|
|
|
|
|
|
|
|
$context->inside_negation = $inside_negation;
|
|
|
|
|
2020-09-30 18:28:13 +02:00
|
|
|
$expr_type = $statements_analyzer->node_data->getType($stmt->expr);
|
|
|
|
|
2021-09-22 16:51:53 +02:00
|
|
|
$stmt_type = Type::getBool();
|
2020-09-30 18:28:13 +02:00
|
|
|
if ($expr_type) {
|
2021-09-22 16:49:16 +02:00
|
|
|
if ($expr_type->isAlwaysTruthy()) {
|
|
|
|
$stmt_type = Type::getFalse();
|
|
|
|
} elseif ($expr_type->isAlwaysFalsy()) {
|
|
|
|
$stmt_type = Type::getTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt_type->from_docblock = $expr_type->from_docblock;
|
2020-09-30 18:28:13 +02:00
|
|
|
$stmt_type->parent_nodes = $expr_type->parent_nodes;
|
|
|
|
}
|
|
|
|
|
2021-09-22 16:51:53 +02:00
|
|
|
$statements_analyzer->node_data->setType($stmt, $stmt_type);
|
|
|
|
|
2020-05-18 21:13:27 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|