1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix issue with nullable types going into docblock

This commit is contained in:
Matthew Brown 2018-01-07 18:06:31 -05:00
parent fe96868e27
commit 66fa081488
3 changed files with 19 additions and 4 deletions

View File

@ -423,7 +423,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
if ($project_checker->alter_code
&& isset($project_checker->getIssuesToFix()['MismatchingDocblockReturnType'])
) {
$this->addOrUpdateReturnType($project_checker, $storage->signature_return_type, true);
$this->addOrUpdateReturnType($project_checker, $storage->signature_return_type);
return null;
}
@ -1331,7 +1331,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
&& !$declared_return_type->isVoid()
) {
if ($project_checker->alter_code
&& isset($project_checker->getIssuesToFix()['UnexpectedNullableReturnType'])
&& isset($project_checker->getIssuesToFix()['InvalidNullableReturnType'])
) {
$this->addOrUpdateReturnType(
$project_checker,

View File

@ -350,7 +350,6 @@ class FunctionDocblockManipulator
}
} elseif ($manipulator->return_typehint_colon_start
&& $manipulator->new_phpdoc_return_type
&& !$manipulator->return_type_is_php_compatible
&& $manipulator->return_typehint_start
&& $manipulator->return_typehint_end
) {

View File

@ -449,7 +449,7 @@ class FileManipulationTest extends TestCase
['InvalidReturnType'],
true,
],
'fixInvalidIntReturnTypeThatIsNotPhpCompatible70' => [
'fixInvalidStringReturnTypeThatIsNotPhpCompatible70' => [
'<?php
function foo() : string {
return rand(0, 1) ? "hello" : false;
@ -465,6 +465,22 @@ class FileManipulationTest extends TestCase
['InvalidFalsableReturnType'],
true,
],
'fixInvalidIntReturnTypeThatIsNotPhpCompatible70' => [
'<?php
function foo() : string {
return rand(0, 1) ? "hello" : null;
}',
'<?php
/**
* @return string|null
*/
function foo() {
return rand(0, 1) ? "hello" : null;
}',
'7.0',
['InvalidNullableReturnType'],
true,
],
'fixInvalidIntReturnTypeJustInTypehintWithComment70' => [
'<?php
function foo() /** cool : beans */ : int /** cool : beans */ {