Skip to content

Commit

Permalink
Emit PhanCommentDuplicate* on comment line
Browse files Browse the repository at this point in the history
Fixes #3636
  • Loading branch information
TysonAndre committed Mar 21, 2020
1 parent 708c9e6 commit d93091a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Expand Up @@ -10,7 +10,7 @@ New features(CLI, Configs):
Add `phan --no-color` option to disable colors.
+ Warn about invalid CLI flags in `phan_client` (#3776)
+ Support representing more AST node types in issue messages. (#3783)
+ Include code fragment for PhanTypeSuspiciousStringExpression (#3745)
+ Make some issue messages easier to read (#3745, #3636)
+ Allow using `--minimum-severity=critical` instead of `--minimum-severity=10` (#3715)

New features(Analysis):
Expand Down
10 changes: 6 additions & 4 deletions src/Phan/Language/Element/Comment.php
Expand Up @@ -239,9 +239,11 @@ public function __construct(
$code_base,
$context,
Issue::CommentDuplicateParam,
$context->getLineNumberStart(),
$parameter->getLineno(),
$name
);
// @phan-suppress-next-line PhanAccessMethodInternal
$parameter->addUnionType($this->parameter_map[$name]->getUnionType());
}
// Add it to the named map
$this->parameter_map[$name] = $parameter;
Expand All @@ -259,7 +261,7 @@ public function __construct(
$code_base,
$context,
Issue::CommentDuplicateMagicProperty,
$context->getLineNumberStart(),
$property->getLine(),
$name
);
}
Expand All @@ -276,7 +278,7 @@ public function __construct(
$code_base,
$context,
Issue::CommentDuplicateMagicMethod,
$context->getLineNumberStart(),
$method->getLine(),
$name
);
}
Expand Down Expand Up @@ -730,7 +732,7 @@ public function __toString(): string
$string .= " * @var $variable\n";
}

foreach (array_merge($this->parameter_map, $this->parameter_list) as $parameter) {
foreach (\array_merge($this->parameter_map, $this->parameter_list) as $parameter) {
$string .= " * @param $parameter\n";
}

Expand Down
12 changes: 12 additions & 0 deletions src/Phan/Language/Element/Comment/Parameter.php
Expand Up @@ -144,6 +144,18 @@ public function getUnionType(): UnionType
return $this->type;
}

/**
* Add types (from another comment) to this comment parameter.
*
* @param UnionType $other
* The type to add to the parameter (for conflicting param tags)
* @internal
*/
public function addUnionType(UnionType $other): void
{
$this->type = $this->type->withUnionType($other);
}

/**
* @return int
* The line number of the parameter
Expand Down
@@ -1,5 +1,5 @@
%s:9 PhanParamReqAfterOpt Required argument follows optional
%s:19 PhanCommentDuplicateMagicMethod Comment declares @method myMethodWithVariadicParams multiple times
%s:17 PhanCommentDuplicateMagicMethod Comment declares @method myMethodWithVariadicParams multiple times
%s:37 PhanUndeclaredMethod Call to undeclared method \A281::undeclaredMagicMethod
%s:38 PhanTypeVoidAssignment Cannot assign void return value
%s:38 PhanUnusedVariable Unused definition of variable $b
Expand Down
@@ -1 +1 @@
%s:10 PhanCommentDuplicateParam Comment declares @param $var multiple times
%s:7 PhanCommentDuplicateParam Comment declares @param $var multiple times
@@ -1,3 +1,3 @@
%s:11 PhanCommentDuplicateMagicProperty Comment declares @property* $intReadProperty multiple times
%s:11 PhanCommentDuplicateMagicProperty Comment declares @property* $mixedProperty multiple times
%s:11 PhanCommentDuplicateMagicProperty Comment declares @property* $stringWriteProperty multiple times
%s:5 PhanCommentDuplicateMagicProperty Comment declares @property* $intReadProperty multiple times
%s:7 PhanCommentDuplicateMagicProperty Comment declares @property* $mixedProperty multiple times
%s:9 PhanCommentDuplicateMagicProperty Comment declares @property* $stringWriteProperty multiple times
4 changes: 2 additions & 2 deletions tests/files/expected/0791_short_array_shape.php.expected
@@ -1,7 +1,7 @@
%s:10 PhanCommentDuplicateParam Comment declares @param $c multiple times
%s:8 PhanCommentDuplicateParam Comment declares @param $c multiple times
%s:10 PhanUndeclaredTypeParameter Parameter $b has undeclared type array<int,\NS781\stdClass> (Did you mean class \stdClass)
%s:11 PhanUnusedVariable Unused definition of variable $val
%s:12 PhanTypeMismatchArgumentInternal Argument 1 ($obj) is $a['Closure']() of type int but \spl_object_hash() takes object
%s:13 PhanTypeMismatchArgumentInternal Argument 1 ($obj) is $cb() of type void but \spl_object_hash() takes object
%s:14 PhanTypeMismatchArgumentInternal Argument 1 ($obj) is $b of type array{0:\NS781\stdClass} but \spl_object_hash() takes object
%s:15 PhanTypeMismatchArgumentInternal Argument 1 ($obj) is $c of type array{0:'',1:array<int,string>,2:'1'} but \spl_object_hash() takes object
%s:15 PhanTypeMismatchArgumentInternal Argument 1 ($obj) is $c of type array{0:'',1:array<int,string>,2:'1'}|array{0:0} but \spl_object_hash() takes object

0 comments on commit d93091a

Please sign in to comment.