1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-16 11:26:55 +01:00
psalm/src/Psalm/Checker/Statements/Block/WhileChecker.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2016-10-22 23:35:59 +02:00
<?php
namespace Psalm\Checker\Statements\Block;
use PhpParser;
2016-11-02 07:29:00 +01:00
use Psalm\Checker\StatementsChecker;
use Psalm\Context;
2016-10-22 23:35:59 +02:00
class WhileChecker
{
/**
2016-11-02 07:29:00 +01:00
* @param StatementsChecker $statements_checker
* @param PhpParser\Node\Stmt\While_ $stmt
* @param Context $context
2017-05-27 02:16:18 +02:00
*
2016-11-02 07:29:00 +01:00
* @return false|null
2016-10-22 23:35:59 +02:00
*/
public static function analyze(
2016-11-02 07:29:00 +01:00
StatementsChecker $statements_checker,
PhpParser\Node\Stmt\While_ $stmt,
Context $context
) {
2016-10-22 23:35:59 +02:00
$while_context = clone $context;
2017-11-30 07:07:20 +01:00
LoopChecker::analyze(
$statements_checker,
$stmt->stmts,
$stmt->cond ? [$stmt->cond] : [],
[],
$while_context,
$context
2016-11-02 07:29:00 +01:00
);
2016-10-22 23:35:59 +02:00
$context->vars_possibly_in_scope = array_merge(
$context->vars_possibly_in_scope,
$while_context->vars_possibly_in_scope
);
$context->referenced_var_ids = array_merge(
$context->referenced_var_ids,
$while_context->referenced_var_ids
);
2016-11-02 07:29:00 +01:00
return null;
2016-10-22 23:35:59 +02:00
}
}