Skip to content
Permalink
Browse files

Migrate static return types

  • Loading branch information
muglug committed Nov 15, 2019
1 parent 4747ba7 commit 55bf6a2db38f13a632912eb806cf6cb632334995
@@ -1194,7 +1194,7 @@ private function alterParams(
$codebase,
$storage->return_type,
$context->self,
$context->self,
'static',
$this->getParentFQCLN(),
false
);
@@ -1218,7 +1218,7 @@ private function alterParams(
$codebase,
$function_param->type,
$context->self,
$context->self,
'static',
$this->getParentFQCLN(),
false
);
@@ -258,7 +258,10 @@ public static function analyze(
}
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,
@@ -89,7 +89,9 @@ public static function analyze(
$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,
@@ -215,11 +215,13 @@ class A extends AParent {
/**
* @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 B extends AParent {
/**
* @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 C {
'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 {

0 comments on commit 55bf6a2

Please sign in to comment.
You can’t perform that action at this time.