1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #1622 - don’t update return types in docblocks when overridden elsewhere

This commit is contained in:
Matthew Brown 2019-05-13 09:04:26 -04:00
parent 9b4d841414
commit f8b4b12ec2
2 changed files with 104 additions and 2 deletions

View File

@ -344,13 +344,20 @@ class ReturnTypeAnalyzer
return null;
}
if ($codebase->alter_code && isset($project_analyzer->getIssuesToFix()['InvalidReturnType'])) {
if ($codebase->alter_code
&& isset($project_analyzer->getIssuesToFix()['InvalidReturnType'])
&& !in_array('InvalidReturnType', $suppressed_issues)
) {
self::addOrUpdateReturnType(
$function,
$project_analyzer,
Type::getVoid(),
$source,
$function_like_analyzer
$function_like_analyzer,
$compatible_method_ids
|| (($project_analyzer->only_replace_php_types_with_non_docblock_types
|| $unsafe_return_type)
&& $inferred_return_type->from_docblock)
);
return null;

View File

@ -1037,6 +1037,101 @@ class ReturnTypeManipulationTest extends FileManipulationTest
['LessSpecificReturnType'],
true,
],
'addMissingReturnTypeWhenParentHasNone' => [
'<?php
class A {
/** @psalm-suppress MissingReturnType */
public function foo() {
return;
}
}
class B extends A {
public function foo() {
return;
}
}',
'<?php
class A {
/** @psalm-suppress MissingReturnType */
public function foo() {
return;
}
}
class B extends A {
/**
* @return void
*/
public function foo() {
return;
}
}',
'7.1',
['MissingReturnType'],
false,
],
'dontAddMissingReturnTypeWhenChildHasNone' => [
'<?php
class A {
public function foo() {}
}
class B extends A {
/** @psalm-suppress MissingReturnType */
public function foo() {}
}',
'<?php
class A {
/**
* @return void
*/
public function foo() {}
}
class B extends A {
/** @psalm-suppress MissingReturnType */
public function foo() {}
}',
'7.1',
['MissingReturnType'],
false,
],
'fixInvalidIntReturnTypeJustInPhpDoc' => [
'<?php
class A {
/**
* @return int
* @psalm-suppress InvalidReturnType
*/
protected function foo() {}
}
class B extends A {
/**
* @return int
*/
protected function foo() {}
}',
'<?php
class A {
/**
* @return int
* @psalm-suppress InvalidReturnType
*/
protected function foo() {}
}
class B extends A {
/**
* @return void
*/
protected function foo() {}
}',
'7.3',
['InvalidReturnType'],
false,
],
];
}
}