2016-10-22 23:35:59 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Checker\Statements\Block;
|
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\Checker\Statements\ExpressionChecker;
|
2016-11-02 07:29:00 +01:00
|
|
|
use Psalm\Checker\StatementsChecker;
|
2017-05-19 06:48:26 +02:00
|
|
|
use Psalm\Context;
|
2016-10-22 23:35:59 +02:00
|
|
|
|
|
|
|
class ForChecker
|
|
|
|
{
|
|
|
|
/**
|
2016-11-02 07:29:00 +01:00
|
|
|
* @param StatementsChecker $statements_checker
|
|
|
|
* @param PhpParser\Node\Stmt\For_ $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
|
|
|
*/
|
2017-01-07 21:09:47 +01:00
|
|
|
public static function analyze(
|
2016-11-02 07:29:00 +01:00
|
|
|
StatementsChecker $statements_checker,
|
|
|
|
PhpParser\Node\Stmt\For_ $stmt,
|
|
|
|
Context $context
|
|
|
|
) {
|
2016-10-22 23:35:59 +02:00
|
|
|
foreach ($stmt->init as $init) {
|
2017-04-11 23:43:46 +02:00
|
|
|
if (ExpressionChecker::analyze($statements_checker, $init, $context) === false) {
|
2016-10-22 23:35:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-11 23:43:46 +02:00
|
|
|
$for_context = clone $context;
|
|
|
|
$for_context->inside_loop = true;
|
|
|
|
|
2017-11-30 07:07:20 +01:00
|
|
|
LoopChecker::analyze($statements_checker, $stmt->stmts, $stmt->cond, $stmt->loop, $for_context, $context);
|
2016-10-22 23:35:59 +02:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
$context->vars_possibly_in_scope = array_merge(
|
|
|
|
$for_context->vars_possibly_in_scope,
|
|
|
|
$context->vars_possibly_in_scope
|
|
|
|
);
|
|
|
|
|
2017-11-24 18:17:28 +01:00
|
|
|
$context->referenced_var_ids = array_merge(
|
|
|
|
$for_context->referenced_var_ids,
|
|
|
|
$context->referenced_var_ids
|
|
|
|
);
|
2017-02-01 05:24:33 +01:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
return null;
|
2016-10-22 23:35:59 +02:00
|
|
|
}
|
|
|
|
}
|