Skip to content

Commit

Permalink
Migrate more things
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Nov 15, 2019
1 parent 5e17a9a commit 4747ba7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,16 @@ function (FunctionLikeParameter $p) {
// fall through
}
}

if ($codebase->alter_code) {
$codebase->classlikes->handleDocblockTypeInMigration(
$codebase,
$this,
$input_type,
$storage->throw_locations[$expected_exception],
$context->calling_method_id
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,12 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
}
}

if ($codebase->alter_code && $fq_class_name && !$moved_call) {
if ($codebase->alter_code
&& $fq_class_name
&& !$moved_call
&& $stmt->class instanceof PhpParser\Node\Name
&& !in_array($stmt->class->parts[0], ['parent', 'static'])
) {
$codebase->classlikes->handleClassLikeReferenceInMigration(
$codebase,
$statements_analyzer,
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Atomic/TArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function toPhpString(

public function canBeFullyExpressedInPhp()
{
return $this->type_params[0]->isMixed() && $this->type_params[1]->isMixed();
return $this->type_params[0]->isArrayKey() && $this->type_params[1]->isMixed();
}

/**
Expand Down
48 changes: 44 additions & 4 deletions tests/FileManipulation/ClassMoveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,56 @@ function foo(B $a) : B {
'<?php
namespace Ns;
class A {
class AParent {
public static function foo(A $one, A $two) {
}
}
class A extends AParent {
/**
* @param self $one
* @param A $two
*/
public static function foo(self $one, A $two) : void {
A::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
}
}
$a = A::class;
$a::foo(new A(), new A());
function foo() {
A::foo(new A(), A::foo());
}',
'<?php
namespace Ns;
class B {
class AParent {
public static function foo(B $one, B $two) {
}
}
class B extends AParent {
/**
* @param self $one
* @param self $two
*/
public static function foo(self $one, self $two) : void {
self::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
}
}
$a = B::class;
$a::foo(new B(), new B());
function foo() {
B::foo(new B(), B::foo());
}',
Expand Down Expand Up @@ -280,10 +304,17 @@ class A {
* @var string
*/
public static $one = "one";
/**
* @var array
*/
public static $vars = ["one"];
}
echo A::$one;
A::$one = "two";',
A::$one = "two";
foreach (A::$vars as $var) {}',
'<?php
namespace Ns;
Expand All @@ -292,10 +323,17 @@ class B {
* @var string
*/
public static $one = "one";
/**
* @var array<array-key, mixed>
*/
public static $vars = ["one"];
}
echo B::$one;
B::$one = "two";',
B::$one = "two";
foreach (B::$vars as $var) {}',
[
'Ns\A' => 'Ns\B',
],
Expand All @@ -310,6 +348,7 @@ class A {
/**
* @param ArrayObject<int, A> $a
* @throws RunTimeException
*/
public function foo(ArrayObject $a) : Exception {
foreach ($a as $b) {
Expand Down Expand Up @@ -343,6 +382,7 @@ class B {
/**
* @param \ArrayObject<int, self> $a
* @throws \RunTimeException
*/
public function foo(\ArrayObject $a) : Exception {
foreach ($a as $b) {
Expand Down

0 comments on commit 4747ba7

Please sign in to comment.