1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #1238 - only emit MissingTemplateParam on direct interface implementers

This commit is contained in:
Brown 2019-01-25 10:10:22 -05:00
parent cd0a7441d9
commit c0f3197790
2 changed files with 50 additions and 16 deletions

View File

@ -277,6 +277,35 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$fq_interface_name
);
}
try {
$interface_storage = $classlike_storage_provider->get($fq_interface_name);
} catch (\InvalidArgumentException $e) {
continue;
}
if ($storage->template_type_extends_count !== null
&& $interface_storage->template_types
&& $storage->template_type_extends_count !== count($interface_storage->template_types)
) {
$code_location = new CodeLocation(
$this,
$interface_name,
$class_context ? $class_context->include_location : null,
true
);
if (IssueBuffer::accepts(
new MissingTemplateParam(
$interface_name . ' has unextended template params, expecting '
. count($interface_storage->template_types),
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
)) {
// fall through
}
}
}
if ($storage->template_type_extends) {
@ -329,22 +358,6 @@ class ClassAnalyzer extends ClassLikeAnalyzer
}
}
if ($storage->template_type_extends_count !== null
&& $interface_storage->template_types
&& $storage->template_type_extends_count !== count($interface_storage->template_types)
) {
if (IssueBuffer::accepts(
new MissingTemplateParam(
$interface_name . ' has unextended template params, expecting '
. count($interface_storage->template_types),
$code_location
),
array_merge($storage->suppressed_issues, $this->getSuppressedIssues())
)) {
// fall through
}
}
foreach ($interface_storage->methods as $method_name => $interface_method_storage) {
if ($interface_method_storage->visibility === self::VISIBILITY_PUBLIC) {
$implementer_declaring_method_id = $codebase->methods->getDeclaringMethodId(

View File

@ -2012,6 +2012,27 @@ class TemplateTest extends TestCase
'$i' => 'Traversable<mixed, mixed>',
]
],
'templateCountOnExtendedAndImplemented' => [
'<?php
/**
* @template TKey
* @template TValue
*/
interface Selectable {}
/**
* @template T
* @template-implements Selectable<int,T>
*/
class Repository implements Selectable {}
interface SomeEntity {}
/**
* @template-extends Repository<SomeEntity>
*/
class SomeRepository extends Repository {}'
],
];
}