1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +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 if ($project_checker->alter_code
&& isset($project_checker->getIssuesToFix()['MismatchingDocblockReturnType']) && isset($project_checker->getIssuesToFix()['MismatchingDocblockReturnType'])
) { ) {
$this->addOrUpdateReturnType($project_checker, $storage->signature_return_type, true); $this->addOrUpdateReturnType($project_checker, $storage->signature_return_type);
return null; return null;
} }
@ -1331,7 +1331,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
&& !$declared_return_type->isVoid() && !$declared_return_type->isVoid()
) { ) {
if ($project_checker->alter_code if ($project_checker->alter_code
&& isset($project_checker->getIssuesToFix()['UnexpectedNullableReturnType']) && isset($project_checker->getIssuesToFix()['InvalidNullableReturnType'])
) { ) {
$this->addOrUpdateReturnType( $this->addOrUpdateReturnType(
$project_checker, $project_checker,

View File

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

View File

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