1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00

New tag @self-out (WIP)

This commit is contained in:
Olle 2020-06-18 20:46:49 +00:00
parent 0f4cd893bd
commit 20cde0ca2c
8 changed files with 49 additions and 1 deletions

View File

@ -467,6 +467,24 @@ class CommentAnalyzer
}
}
if (isset($parsed_docblock->tags['self-out'])) {
foreach ($parsed_docblock->tags['param-out'] as $offset => $param) {
$line_parts = self::splitDocLine($param);
if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') {
continue;
}
if (count($line_parts) > 1) {
$line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0]));
$info->self_out[] = [
'type' => str_replace("\n", '', $line_parts[0]),
'line_number' => $comment->getLine() + substr_count($comment_text, "\n", 0, $offset),
];
}
}
}
if (isset($parsed_docblock->tags['psalm-flow'])) {
$flow = trim(reset($parsed_docblock->tags['psalm-flow']));
$info->flow = $flow;

View File

@ -1509,7 +1509,11 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
),
$statements_analyzer->getSuppressedIssues()
)) {
//var_dump($actual_type->getId());
//var_dump($context);
//die;
// fall through
//throw new \Exception('there');
}
}
}

View File

@ -1016,6 +1016,10 @@ class PropertyAssignmentAnalyzer
),
$statements_analyzer->getSuppressedIssues()
)) {
//var_dump($context);
//$context->vars_in_scope['$this->t'] = new \Psalm\Type\Atomic\TNamedObject("Closed");
//die;
//throw new \Exception('here');
return false;
}
} else {

View File

@ -1297,13 +1297,18 @@ class AssignmentAnalyzer
return;
}
$var_id = ExpressionIdentifier::getVarId(
$stmt,
$statements_analyzer->getFQCLN(),
$statements_analyzer
);
//$var_id = '$f';
//$context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);
//$context->vars_possibly_in_scope[$var_id] = true;
//$context->vars_in_scope[$var_id] = new Type\Union([new Type\Atomic\TInt()]);
//return;
if ($var_id) {
if (!$by_ref_type->hasMixed() && $constrain_type) {
$context->byref_constraints[$var_id] = new \Psalm\Internal\ReferenceConstraint($by_ref_type);

View File

@ -829,9 +829,13 @@ class ArgumentsAnalyzer
]);
}
}
//var_dump($by_ref_type);die;
$by_ref_type = $by_ref_type ?: Type::getMixed();
//var_dump($by_ref_type);
//var_dump($by_ref_out_type);
AssignmentAnalyzer::assignByRefParam(
$statements_analyzer,
$arg->value,

View File

@ -85,6 +85,8 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
? $context->vars_in_scope[$lhs_var_id]
: null;
var_dump($class_type);
if ($stmt_var_type = $statements_analyzer->node_data->getType($stmt->var)) {
$class_type = $stmt_var_type;
} elseif (!$class_type) {
@ -360,6 +362,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
);
}
var_dump($result->existent_method_ids);
if (!$result->existent_method_ids) {
return self::checkMethodArgs(
null,

View File

@ -2439,6 +2439,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
$class_template_types = $this->class_template_types;
foreach ($docblock_info->params_out as $docblock_param_out) {
$param_name = substr($docblock_param_out['name'], 1);
try {
@ -2475,6 +2476,10 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
}
}
foreach ($docblock_info->self_out as $self_out) {
var_dump($self_out);
}
foreach ($docblock_info->taint_sink_params as $taint_sink_param) {
$param_name = substr($taint_sink_param['name'], 1);

View File

@ -41,6 +41,11 @@ class FunctionDocblockComment
*/
public $params_out = [];
/**
* @var array<int, array{type:string, line_number: int}>
*/
public $self_out = [];
/**
* @var array<int, array{name:string, type:string, line_number: int}>
*/