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

Migrate static return types

This commit is contained in:
Brown 2019-11-15 16:50:43 -05:00
parent 4747ba709a
commit 55bf6a2db3
4 changed files with 97 additions and 4 deletions

View File

@ -1194,7 +1194,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer implements Statements
$codebase,
$storage->return_type,
$context->self,
$context->self,
'static',
$this->getParentFQCLN(),
false
);
@ -1218,7 +1218,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer implements Statements
$codebase,
$function_param->type,
$context->self,
$context->self,
'static',
$this->getParentFQCLN(),
false
);

View File

@ -258,7 +258,10 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
}
if ($fq_class_name) {
if ($codebase->alter_code) {
if ($codebase->alter_code
&& $stmt->class instanceof PhpParser\Node\Name
&& !in_array($stmt->class->parts[0], ['parent', 'static'])
) {
$codebase->classlikes->handleClassLikeReferenceInMigration(
$codebase,
$statements_analyzer,

View File

@ -89,7 +89,9 @@ class ClassConstFetchAnalyzer
$moved_class = false;
if ($codebase->alter_code) {
if ($codebase->alter_code
&& !in_array($stmt->class->parts[0], ['parent', 'static'])
) {
$moved_class = $codebase->classlikes->handleClassLikeReferenceInMigration(
$codebase,
$statements_analyzer,

View File

@ -215,11 +215,13 @@ class ClassMoveTest extends \Psalm\Tests\TestCase
/**
* @param self $one
* @param A $two
* @return static
*/
public static function foo(self $one, A $two) : void {
A::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
return new static();
}
}
@ -243,11 +245,13 @@ class ClassMoveTest extends \Psalm\Tests\TestCase
/**
* @param self $one
* @param self $two
* @return static
*/
public static function foo(self $one, self $two) : void {
self::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
return new static();
}
}
@ -540,6 +544,90 @@ class ClassMoveTest extends \Psalm\Tests\TestCase
'Foo\B' => 'Bar\Baz\B',
],
],
'moveClassesIntoNamespaceWithoutAlias' => [
'<?php
namespace Foo {
class A {
/** @var ?B */
public $x = null;
/** @var ?A */
public $y = null;
/** @var A|B|C|null */
public $z = null;
public static $vars = [1, 2, 3];
}
}
namespace Foo {
class B {
/** @var ?A */
public $x = null;
/** @var ?B */
public $y = null;
/** @var A|B|C|null */
public $z = null;
}
foreach (A::$vars[$foo] as $var) {}
}
namespace Bar {
class C {
/** @var ?\Foo\A */
public $x = null;
/** @var ?\Foo\B */
public $y = null;
/** @var \Foo\A|\Foo\B|null */
public $z = null;
}
foreach (\Foo\A::$vars as $var) {}
}',
'<?php
namespace Bar\Baz {
class A {
/** @var B|null */
public $x = null;
/** @var null|self */
public $y = null;
/** @var B|\Foo\C|null|self */
public $z = null;
public static $vars = [1, 2, 3];
}
}
namespace Bar\Baz {
class B {
/** @var A|null */
public $x = null;
/** @var null|self */
public $y = null;
/** @var A|\Foo\C|null|self */
public $z = null;
}
foreach (\Bar\Baz\A::$vars[$foo] as $var) {}
}
namespace Bar {
class C {
/** @var Baz\A|null */
public $x = null;
/** @var Baz\B|null */
public $y = null;
/** @var Baz\A|Baz\B|null */
public $z = null;
}
foreach (Baz\A::$vars as $var) {}
}',
[
'Foo\A' => 'Bar\Baz\A',
'Foo\B' => 'Bar\Baz\B',
],
],
'moveClassDeeperIntoNamespaceAdjustUseWithAlias' => [
'<?php
namespace Foo {