1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix errors

This commit is contained in:
bugreportuser 2019-02-18 12:51:27 -06:00 committed by Matthew Brown
parent cd23a19931
commit 14ee221075
3 changed files with 30 additions and 24 deletions

View File

@ -607,17 +607,21 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
return false;
}
} elseif ($function->parts === ['define']) {
$const_name = StatementsAnalyzer::getConstName($first_arg->value);
if ($first_arg) {
$const_name = StatementsAnalyzer::getConstName($first_arg->value);
if ($const_name !== null) {
$second_arg = $stmt->args[1];
ExpressionAnalyzer::analyze($statements_analyzer, $second_arg->value, $context);
if ($const_name !== null) {
$second_arg = $stmt->args[1];
ExpressionAnalyzer::analyze($statements_analyzer, $second_arg->value, $context);
$statements_analyzer->setConstType(
$const_name,
isset($second_arg->value->inferredType) ? $second_arg->value->inferredType : Type::getMixed(),
$context
);
$statements_analyzer->setConstType(
$const_name,
isset($second_arg->value->inferredType) ?
$second_arg->value->inferredType :
Type::getMixed(),
$context
);
}
} else {
$context->check_consts = false;
}

View File

@ -1467,7 +1467,7 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
}
/**
* @param mixed $first_arg_value
* @param PhpParser\Node\Expr $first_arg_value
*
* @return null|string
*/

View File

@ -588,20 +588,22 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
if ($function_id === 'define') {
$first_arg_value = isset($node->args[0]) ? $node->args[0]->value : null;
$second_arg_value = isset($node->args[1]) ? $node->args[1]->value : null;
$const_name = StatementsAnalyzer::getConstName($first_arg_value);
if ($const_name !== null && $second_arg_value) {
$const_type = StatementsAnalyzer::getSimpleType(
$this->codebase,
$second_arg_value,
$this->aliases
) ?: Type::getMixed();
if ($this->functionlike_storages && !$this->config->hoist_constants) {
$functionlike_storage =
$this->functionlike_storages[count($this->functionlike_storages) - 1];
$functionlike_storage->defined_constants[$const_name] = $const_type;
} else {
$this->file_storage->constants[$const_name] = $const_type;
$this->file_storage->declaring_constants[$const_name] = $this->file_path;
if ($first_arg_value && $second_arg_value) {
$const_name = StatementsAnalyzer::getConstName($first_arg_value);
if ($const_name !== null) {
$const_type = StatementsAnalyzer::getSimpleType(
$this->codebase,
$second_arg_value,
$this->aliases
) ?: Type::getMixed();
if ($this->functionlike_storages && !$this->config->hoist_constants) {
$functionlike_storage =
$this->functionlike_storages[count($this->functionlike_storages) - 1];
$functionlike_storage->defined_constants[$const_name] = $const_type;
} else {
$this->file_storage->constants[$const_name] = $const_type;
$this->file_storage->declaring_constants[$const_name] = $this->file_path;
}
}
}
}