Skip to content
Permalink
Browse files

Fix namespaced method moving

  • Loading branch information...
muglug committed Jun 1, 2019
1 parent cc89b92 commit a252fb84daa5d6531002cb7b2dc5c875e1ff00c8
@@ -144,6 +144,7 @@ public static function analyzeClassConst(
&& $context->calling_method_id
&& isset($codebase->method_migrations[strtolower($context->calling_method_id)])
&& strtolower(explode('::', $context->calling_method_id)[0]) === strtolower($fq_class_name)
&& !$stmt->class instanceof PhpParser\Node\Name\FullyQualified
) {
$file_manipulations = [];
@@ -152,8 +153,8 @@ public static function analyzeClassConst(
(int) $stmt->class->getAttribute('endFilePos') + 1,
Type::getStringFromFQCLN(
$fq_class_name,
$statements_analyzer->getNamespace(),
$statements_analyzer->getAliasedClassesFlipped(),
null,
[],
null
)
);
@@ -87,6 +87,8 @@ public function providerValidCodeParse()
return [
'moveStaticMethodReferenceOnly' => [
'<?php
namespace Ns;
class A {
const C = 5;
@@ -104,6 +106,8 @@ public static function bar() : void {
}
}',
'<?php
namespace Ns;
class A {
const C = 5;
@@ -122,11 +126,13 @@ public static function bar() : void {
}',
[],
[
'a::foo\((.*\))' => 'B::Fe($1)',
'ns\a::foo\((.*\))' => 'Ns\B::Fe($1)',
]
],
'moveEmptyStaticMethodOnly' => [
'<?php
namespace Ns;
class A {
/**
* @return void
@@ -137,6 +143,8 @@ public static function Foo() : void {}
class B {
}',
'<?php
namespace Ns;
class A {
}
@@ -149,13 +157,15 @@ class B {
public static function Fedcba() : void {}
}',
[
'a::foo' => 'B::Fedcba',
'ns\a::foo' => 'Ns\B::Fedcba',
],
[
]
],
'moveEmptyStaticMethodShorterOnly' => [
'<?php
namespace Ns;
class A {
/**
* @return void
@@ -166,6 +176,8 @@ public static function Fedbca() : void {}
class B {
}',
'<?php
namespace Ns;
class A {
}
@@ -178,13 +190,15 @@ class B {
public static function Foo() : void {}
}',
[
'a::fedbca' => 'B::Foo',
'ns\a::fedbca' => 'Ns\B::Foo',
],
[
]
],
'moveStaticMethodOnly' => [
'<?php
namespace Ns;
class A {
const C = 5;
@@ -199,6 +213,8 @@ public static function Foo() : void {
class B {
}',
'<?php
namespace Ns;
class A {
const C = 5;
@@ -211,16 +227,18 @@ class B {
* @return void
*/
public static function Fedbca() : void {
echo A::C;
echo \Ns\A::C;
}
}',
[
'a::foo' => 'B::Fedbca',
'ns\a::foo' => 'Ns\B::Fedbca',
],
[]
],
'moveStaticMethodShorterOnly' => [
'<?php
namespace Ns;
class A {
const C = 5;
@@ -235,6 +253,8 @@ public static function Fedbca() : void {
class B {
}',
'<?php
namespace Ns;
class A {
const C = 5;
@@ -247,16 +267,18 @@ class B {
* @return void
*/
public static function Foo() : void {
echo A::C;
echo \Ns\A::C;
}
}',
[
'a::fedbca' => 'B::Foo',
'ns\a::fedbca' => 'Ns\B::Foo',
],
[]
],
'moveStaticMethodAndReferencesFromAbove' => [
'<?php
namespace Ns;
class A {
const C = 5;
@@ -274,6 +296,8 @@ public static function bar() : void {
}
}',
'<?php
namespace Ns;
class A {
const C = 5;
@@ -289,18 +313,20 @@ public static function bar() : void {
* @return void
*/
public static function Fe() : void {
echo A::C;
echo \Ns\A::C;
}
}',
[
'a::foo' => 'B::Fe',
'ns\a::foo' => 'Ns\B::Fe',
],
[
'a::foo\((.*\))' => 'B::Fe($1)',
'ns\a::foo\((.*\))' => 'Ns\B::Fe($1)',
]
],
'moveStaticMethodAndReferencesFromBelow' => [
'<?php
namespace Ns;
class B {
public static function bar() : void {
A::Foo();
@@ -318,6 +344,8 @@ public static function Foo() : void {
}
}',
'<?php
namespace Ns;
class B {
public static function bar() : void {
B::Fe();
@@ -327,7 +355,7 @@ public static function bar() : void {
* @return void
*/
public static function Fe() : void {
echo A::C;
echo \Ns\A::C;
}
}
@@ -336,12 +364,64 @@ class A {
}',
[
'a::foo' => 'B::Fe',
'ns\a::foo' => 'Ns\B::Fe',
],
[
'ns\a::foo\((.*\))' => 'Ns\B::Fe($1)',
]
],
'moveStaticMethodAndReferencesAcrossNamespaces' => [
'<?php
namespace Ns1 {
class A {
const C = 5;
/**
* @return void
*/
public static function Foo() : void {
echo self::C;
}
}
}
namespace Ns2\Ns3 {
class B {
public static function bar() : void {
\Ns1\A::Foo();
}
}
}',
'<?php
namespace Ns1 {
class A {
const C = 5;
}
}
namespace Ns2\Ns3 {
class B {
public static function bar() : void {
B::Fe();
}
/**
* @return void
*/
public static function Fe() : void {
echo \Ns1\A::C;
}
}
}',
[
'ns1\a::foo' => 'Ns2\Ns3\B::Fe',
],
[
'a::foo\((.*\))' => 'B::Fe($1)',
'ns1\a::foo\((.*\))' => 'Ns2\Ns3\B::Fe($1)',
]
]
],
];
}
}

0 comments on commit a252fb8

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