Skip to content
Permalink
Browse files

Allow explicit @var mixed docblocks

Fixes #2397
  • Loading branch information
muglug committed Dec 1, 2019
1 parent f36766b commit e40aaafe61af2a049cefb59b0a868fb00a465989
@@ -154,6 +154,7 @@ public static function analyze(
&& $type_location
&& isset($context->vars_in_scope[$var_comment->var_id])
&& $context->vars_in_scope[$var_comment->var_id]->getId() === $comment_type->getId()
&& !$comment_type->isMixed()
) {
$project_analyzer = $statements_analyzer->getProjectAnalyzer();
@@ -163,7 +164,8 @@ public static function analyze(
FileManipulationBuffer::addVarAnnotationToRemove($type_location);
} elseif (IssueBuffer::accepts(
new UnnecessaryVarAnnotation(
'The @var annotation for ' . $var_comment->var_id . ' is unnecessary',
'The @var ' . $comment_type . ' annotation for '
. $var_comment->var_id . ' is unnecessary',
$type_location
)
)) {
@@ -177,6 +177,7 @@ public static function analyze(
&& $type_location
&& isset($context->vars_in_scope[$var_comment->var_id])
&& $context->vars_in_scope[$var_comment->var_id]->getId() === $var_comment_type->getId()
&& !$comment_type->isMixed()
) {
$project_analyzer = $statements_analyzer->getProjectAnalyzer();
@@ -186,7 +187,8 @@ public static function analyze(
FileManipulationBuffer::addVarAnnotationToRemove($type_location);
} elseif (IssueBuffer::accepts(
new UnnecessaryVarAnnotation(
'The @var annotation for ' . $var_comment->var_id . ' is unnecessary',
'The @var ' . $var_comment . ' annotation for '
. $var_comment->var_id . ' is unnecessary',
$type_location
)
)) {
@@ -248,14 +250,16 @@ public static function analyze(
&& $temp_assign_value_type
&& $array_var_id
&& $temp_assign_value_type->getId() === $comment_type->getId()
&& !$comment_type->isMixed()
) {
if ($codebase->alter_code
&& isset($statements_analyzer->getProjectAnalyzer()->getIssuesToFix()['UnnecessaryVarAnnotation'])
) {
FileManipulationBuffer::addVarAnnotationToRemove($comment_type_location);
} elseif (IssueBuffer::accepts(
new UnnecessaryVarAnnotation(
'The @var annotation for ' . $array_var_id . ' is unnecessary',
'The @var ' . $comment_type . ' annotation for '
. $array_var_id . ' is unnecessary',
$comment_type_location
)
)) {
@@ -1306,6 +1306,17 @@ function foo($a): void {
$a->foo(new Exception($m));
}',
],
'validMixedAnnotation' => [
'<?php
function keys(): array {
return ["foo", "bar"];
}
/** @var mixed $k */
foreach (keys() as $k) {
echo gettype($k);
}'
],
];
}

0 comments on commit e40aaaf

Please sign in to comment.
You can’t perform that action at this time.