Skip to content

Commit

Permalink
Fix #2491 - report trait issues at the most local place
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 20, 2019
1 parent 1b54d05 commit a5434aa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/Psalm/Internal/Analyzer/MethodAnalyzer.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ public static function compareMethods(
$prevent_abstract_override = true, $prevent_abstract_override = true,
$prevent_method_signature_mismatch = true $prevent_method_signature_mismatch = true
) { ) {
$config = $codebase->config;

$implementer_method_id = $implementer_classlike_storage->name . '::' $implementer_method_id = $implementer_classlike_storage->name . '::'
. strtolower($guide_method_storage->cased_name ?: ''); . strtolower($guide_method_storage->cased_name ?: '');


Expand Down Expand Up @@ -803,7 +805,11 @@ public static function compareMethods(
. 'return type for ' . $implementer_declaring_method_id . ' \'' . 'return type for ' . $implementer_declaring_method_id . ' \''
. $implementer_method_storage_return_type->getId() . '\'', . $implementer_method_storage_return_type->getId() . '\'',
$implementer_method_storage->return_type_location $implementer_method_storage->return_type_location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->return_type_location->file_path
)
? $implementer_method_storage->return_type_location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand All @@ -817,7 +823,11 @@ public static function compareMethods(
. 'return type for ' . $implementer_declaring_method_id . ' \'' . 'return type for ' . $implementer_declaring_method_id . ' \''
. $implementer_method_storage_return_type->getId() . '\'', . $implementer_method_storage_return_type->getId() . '\'',
$implementer_method_storage->return_type_location $implementer_method_storage->return_type_location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->return_type_location->file_path
)
? $implementer_method_storage->return_type_location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand Down Expand Up @@ -888,7 +898,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' . $guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
) )
)) { )) {
return false; return false;
Expand Down Expand Up @@ -942,7 +956,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' . $guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
) )
)) { )) {
return false; return false;
Expand All @@ -955,7 +973,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' . $guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand Down Expand Up @@ -1080,7 +1102,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' . $guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand All @@ -1103,7 +1129,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' . $guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand All @@ -1118,7 +1148,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' . $guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id, $cased_guide_method_id,
$implementer_method_storage->params[$i]->location $implementer_method_storage->params[$i]->location
?: $code_location && $config->isInProjectDirs(
$implementer_method_storage->params[$i]->location->file_path
)
? $implementer_method_storage->params[$i]->location
: $code_location
), ),
$suppressed_issues $suppressed_issues
)) { )) {
Expand Down
35 changes: 35 additions & 0 deletions tests/TraitTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -885,6 +885,41 @@ public function bar() {
} }
}' }'
], ],
'classAliasedTrait' => [
'<?php
trait FeatureV1 {}
class_alias(FeatureV1::class, Feature::class);
class Application {
use Feature;
}',
],
'inheritBad' => [
'<?php
interface FooBarInterface
{
/**
* @param string $parameter
*/
public function foo($parameter): void;
}
trait FooBarTrait
{
/**
* @param string $parameter
*/
public function foo(string $parameter): void
{
}
}
class FooBar implements FooBarInterface
{
use FooBarTrait;
}'
],
]; ];
} }


Expand Down

0 comments on commit a5434aa

Please sign in to comment.