Skip to content

Commit

Permalink
Add dupe key for MethodSignatureMismatch issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jan 24, 2022
1 parent 8230efb commit c073ca3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,8 @@ private function checkImplementedInterfaces(
'Method ' . $implementer_method_storage->cased_name
. ' should be static like '
. $storage->name . '::' . $interface_method_storage->cased_name,
$code_location
$code_location,
$implementer_method_storage->cased_name . ' static'
),
$implementer_method_storage->suppressed_issues
);
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ public function analyze(
IssueBuffer::maybeAdd(new MethodSignatureMismatch(
'Method ' . (string) $method_id . ' should accept named arguments '
. ' as ' . (string) $overridden_method_id . ' does',
$storage->location
$storage->location,
$method_id . ' no named arguments'
));
}
}
Expand Down
33 changes: 22 additions & 11 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ function (AttributeStorage $s) {
new MethodSignatureMismatch(
'Method ' . $cased_implementer_method_id . ' has fewer parameters than parent method ' .
$cased_guide_method_id,
$code_location
$code_location,
$cased_implementer_method_id . ' not enough parameters'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
)) {
Expand Down Expand Up @@ -212,7 +213,8 @@ function (AttributeStorage $s) {
new MethodSignatureMismatch(
'Method ' . $cased_implementer_method_id . ' has more required parameters than parent method ' .
$cased_guide_method_id,
$code_location
$code_location,
$cased_implementer_method_id . ' too many parameters'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
)) {
Expand Down Expand Up @@ -276,7 +278,8 @@ private static function checkForObviousMethodMismatches(
new TraitMethodSignatureMismatch(
'Method ' . $cased_implementer_method_id . ' has different access level than '
. $cased_guide_method_id,
$code_location
$code_location,
$cased_implementer_method_id . ' wrong access level'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
)) {
Expand All @@ -291,7 +294,8 @@ private static function checkForObviousMethodMismatches(
IssueBuffer::maybeAdd(
new MethodSignatureMismatch(
'Method ' . $cased_guide_method_id . ' is declared final and cannot be overridden',
$code_location
$code_location,
$cased_implementer_method_id . ' final'
),
$guide_method_storage->final_from_docblock ?
$suppressed_issues + $implementer_classlike_storage->suppressed_issues :
Expand All @@ -309,7 +313,8 @@ private static function checkForObviousMethodMismatches(
new MethodSignatureMismatch(
'Method ' . $cased_implementer_method_id . ' cannot be abstract when inherited method '
. $cased_guide_method_id . ' is non-abstract',
$code_location
$code_location,
$cased_implementer_method_id . ' cannot be abstract'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand Down Expand Up @@ -418,7 +423,8 @@ private static function compareMethodParams(
$implementer_param->location->file_path
)
? $implementer_param->location
: $code_location
: $code_location,
$cased_implementer_method_id . ' wrong type param ' . ($i + 1)
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand Down Expand Up @@ -537,7 +543,8 @@ private static function compareMethodParams(
$implementer_param->location->file_path
)
? $implementer_param->location
: $code_location
: $code_location,
$cased_implementer_method_id . ' ref param ' . ($i + 1)
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand Down Expand Up @@ -640,7 +647,8 @@ private static function compareMethodSignatureParams(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
: $code_location,
$cased_implementer_method_id . ' wrong signature type ' . ($i + 1)
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand All @@ -657,7 +665,8 @@ private static function compareMethodSignatureParams(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
: $code_location,
$cased_implementer_method_id . ' wrong signature type ' . ($i + 1)
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand Down Expand Up @@ -910,7 +919,8 @@ private static function compareMethodSignatureReturnTypes(
'Method ' . $cased_implementer_method_id . ' with return type \''
. $implementer_signature_return_type . '\' is different to return type \''
. $guide_signature_return_type . '\' of inherited method ' . $cased_guide_method_id,
$code_location
$code_location,
$cased_implementer_method_id . ' wrong return type'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand All @@ -920,7 +930,8 @@ private static function compareMethodSignatureReturnTypes(
'Method ' . $cased_implementer_method_id . ' with return type \''
. $implementer_signature_return_type . '\' is different to return type \''
. $guide_signature_return_type . '\' of inherited method ' . $cased_guide_method_id,
$code_location
$code_location,
$cased_implementer_method_id . ' wrong return type'
),
$suppressed_issues + $implementer_classlike_storage->suppressed_issues
);
Expand Down
9 changes: 9 additions & 0 deletions src/Psalm/Issue/MethodSignatureMismatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

namespace Psalm\Issue;

use Psalm\CodeLocation;

class MethodSignatureMismatch extends CodeIssue
{
public const ERROR_LEVEL = 7;
public const SHORTCODE = 42;

public function __construct(string $message, CodeLocation $code_location, ?string $dupe_key)
{
parent::__construct($message, $code_location);

$this->dupe_key = $dupe_key;
}
}
9 changes: 9 additions & 0 deletions src/Psalm/Issue/TraitMethodSignatureMismatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

namespace Psalm\Issue;

use Psalm\CodeLocation;

class TraitMethodSignatureMismatch extends CodeIssue
{
public const ERROR_LEVEL = 6;
public const SHORTCODE = 192;

public function __construct(string $message, CodeLocation $code_location, ?string $dupe_key)
{
parent::__construct($message, $code_location);

$this->dupe_key = $dupe_key;
}
}

0 comments on commit c073ca3

Please sign in to comment.