Skip to content
Permalink
Browse files

Fix #2491 - report trait issues at the most local place

  • Loading branch information
muglug committed Dec 20, 2019
1 parent 1b54d05 commit a5434aabfe667287a7092a8b6bf657232cd257b0
Showing with 77 additions and 8 deletions.
  1. +42 −8 src/Psalm/Internal/Analyzer/MethodAnalyzer.php
  2. +35 −0 tests/TraitTest.php
@@ -519,6 +519,8 @@ public static function compareMethods(
$prevent_abstract_override = true,
$prevent_method_signature_mismatch = true
) {
$config = $codebase->config;

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

@@ -803,7 +805,11 @@ public static function compareMethods(
. 'return type for ' . $implementer_declaring_method_id . ' \''
. $implementer_method_storage_return_type->getId() . '\'',
$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
)) {
@@ -817,7 +823,11 @@ public static function compareMethods(
. 'return type for ' . $implementer_declaring_method_id . ' \''
. $implementer_method_storage_return_type->getId() . '\'',
$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
)) {
@@ -888,7 +898,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id,
$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;
@@ -942,7 +956,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id,
$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;
@@ -955,7 +973,11 @@ public static function compareMethods(
$guide_param_signature_type . '\' as defined by ' .
$cased_guide_method_id,
$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
)) {
@@ -1080,7 +1102,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$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
)) {
@@ -1103,7 +1129,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$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
)) {
@@ -1118,7 +1148,11 @@ public static function compareMethods(
$guide_method_storage_param_type->getId() . '\' as defined by ' .
$cased_guide_method_id,
$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
)) {
@@ -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;
}'
],
];
}

0 comments on commit a5434aa

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