mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Don’t update return types to null
This commit is contained in:
parent
e58e824af3
commit
e249c27308
@ -1258,7 +1258,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
if ($project_checker->alter_code
|
||||
&& isset($project_checker->getIssuesToFix()['MissingClosureReturnType'])
|
||||
) {
|
||||
if ($inferred_return_type->isMixed()) {
|
||||
if ($inferred_return_type->isMixed() || $inferred_return_type->isNull()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1288,7 +1288,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
if ($project_checker->alter_code
|
||||
&& isset($project_checker->getIssuesToFix()['MissingReturnType'])
|
||||
) {
|
||||
if ($inferred_return_type->isMixed()) {
|
||||
if ($inferred_return_type->isMixed() || $inferred_return_type->isNull()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1383,6 +1383,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
) {
|
||||
if ($project_checker->alter_code
|
||||
&& isset($project_checker->getIssuesToFix()['InvalidNullableReturnType'])
|
||||
&& !$inferred_return_type->isNull()
|
||||
) {
|
||||
$this->addOrUpdateReturnType(
|
||||
$project_checker,
|
||||
|
@ -60,7 +60,7 @@ class TNamedObject extends Atomic
|
||||
$class_name = array_pop($class_parts);
|
||||
|
||||
if ($this->value === $this_class) {
|
||||
return $class_name;
|
||||
return 'self';
|
||||
}
|
||||
|
||||
if ($namespace && preg_match('/^' . preg_quote($namespace) . '\\\\' . $class_name . '$/i', $this->value)) {
|
||||
|
@ -415,6 +415,42 @@ class FileManipulationTest extends TestCase
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
],
|
||||
'addSelfReturnType' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function foo() {
|
||||
return $this;
|
||||
}
|
||||
}',
|
||||
'<?php
|
||||
class A {
|
||||
public function foo(): self {
|
||||
return $this;
|
||||
}
|
||||
}',
|
||||
'7.1',
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
],
|
||||
'dontAddMissingVoidReturnType56' => [
|
||||
'<?php
|
||||
/** @return void */
|
||||
function foo() { }
|
||||
|
||||
function bar() {
|
||||
return foo();
|
||||
}',
|
||||
'<?php
|
||||
/** @return void */
|
||||
function foo() { }
|
||||
|
||||
function bar() {
|
||||
return foo();
|
||||
}',
|
||||
'5.6',
|
||||
['MissingReturnType'],
|
||||
true,
|
||||
],
|
||||
'fixInvalidIntReturnType56' => [
|
||||
'<?php
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user