Skip to content
Permalink
Browse files

Preserve self refs where possible

  • Loading branch information
muglug committed Nov 17, 2019
1 parent 7d7d4dd commit 2369bac943aecc3a02eae762835a92437c91c62a
@@ -1149,7 +1149,9 @@ private function alterParams(
$this,
$param_name_node,
$resolved_name,
$context->calling_method_id
$context->calling_method_id,
false,
true
);
}
}
@@ -1181,7 +1183,9 @@ private function alterParams(
$this,
$return_name_node,
$resolved_name,
$context->calling_method_id
$context->calling_method_id,
false,
true
);
}
}
@@ -974,7 +974,8 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
$stmt->class,
$new_fq_class_name,
$context->calling_method_id,
strtolower($old_declaring_fq_class_name) !== strtolower($new_fq_class_name)
strtolower($old_declaring_fq_class_name) !== strtolower($new_fq_class_name),
$stmt->class->parts[0] === 'self'
)) {
$moved_call = true;
}
@@ -1087,7 +1088,9 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
$statements_analyzer,
$stmt->class,
$fq_class_name,
$context->calling_method_id
$context->calling_method_id,
false,
$stmt->class->parts[0] === 'self'
);
}
@@ -97,7 +97,9 @@ public static function analyze(
$statements_analyzer,
$stmt->class,
$fq_class_name,
$context->calling_method_id
$context->calling_method_id,
false,
$stmt->class->parts[0] === 'self'
);
}
@@ -1027,7 +1027,8 @@ public function handleClassLikeReferenceInMigration(
PhpParser\Node $class_name_node,
string $fq_class_name,
?string $calling_method_id,
bool $force_change = false
bool $force_change = false,
bool $was_self = false
) : bool {
$calling_fq_class_name = $source->getFQCLN();
@@ -1050,7 +1051,8 @@ public function handleClassLikeReferenceInMigration(
$source->getFilePath(),
(int) $class_name_node->getAttribute('startFilePos'),
(int) $class_name_node->getAttribute('endFilePos') + 1,
$class_name_node instanceof PhpParser\Node\Scalar\MagicConst\Class_
$class_name_node instanceof PhpParser\Node\Scalar\MagicConst\Class_,
$was_self
);
return true;
@@ -1120,7 +1122,8 @@ public function handleClassLikeReferenceInMigration(
$new_fq_class_name,
$source_namespace,
$uses_flipped,
$migrated_source_fqcln
$migrated_source_fqcln,
$was_self
)
. ($class_name_node instanceof PhpParser\Node\Scalar\MagicConst\Class_ ? '::class' : '')
);
@@ -1330,7 +1333,8 @@ public function airliftClassLikeReference(
string $source_file_path,
int $source_start,
int $source_end,
bool $add_class_constant = false
bool $add_class_constant = false,
bool $allow_self = false
) : void {
$project_analyzer = \Psalm\Internal\Analyzer\ProjectAnalyzer::getInstance();
$codebase = $project_analyzer->getCodebase();
@@ -1350,7 +1354,8 @@ public function airliftClassLikeReference(
$fq_class_name,
$destination_class_storage->aliases->namespace,
$destination_class_storage->aliases->uses_flipped,
$destination_class_storage->name
$destination_class_storage->name,
$allow_self
) . ($add_class_constant ? '::class' : '')
);
@@ -1100,9 +1100,10 @@ public static function getStringFromFQCLN(
string $value,
?string $namespace,
array $aliased_classes,
?string $this_class
?string $this_class,
bool $allow_self = false
) : string {
if ($value === $this_class) {
if ($allow_self && $value === $this_class) {
return 'self';
}
@@ -77,7 +77,8 @@ public function toNamespacedString(
$use_phpdoc_format
);
return Type::getStringFromFQCLN($this->value, $namespace, $aliased_classes, $this_class) . $intersection_types;
return Type::getStringFromFQCLN($this->value, $namespace, $aliased_classes, $this_class, true)
. $intersection_types;
}
/**
@@ -219,6 +219,7 @@ class A extends AParent {
*/
public static function foo(self $one, A $two) : void {
A::foo($one, $two);
self::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
return new static();
@@ -248,6 +249,7 @@ class B extends AParent {
* @return static
*/
public static function foo(self $one, self $two) : void {
B::foo($one, $two);
self::foo($one, $two);
parent::foo($one, $two);
static::foo($one, $two);
@@ -367,6 +369,7 @@ public function foo(ArrayObject $a) : Exception {
echo \A::class;
echo __CLASS__;
echo self::class;
ArrayObject::foo();
@@ -399,7 +402,8 @@ public function foo(\ArrayObject $a) : Exception {
}
echo self::class;
echo B::class;
echo B::class;
echo self::class;
\ArrayObject::foo();
@@ -116,8 +116,8 @@ class A {
class B {
public static function bar() : void {
self::Fe();
foreach (self::Fe() as $f) {}
B::Fe();
foreach (B::Fe() as $f) {}
}
/**
@@ -356,11 +356,11 @@ public static function Fedbca(A $a1, ?A $a2, array $a3) : A {
echo A::C;
A::Bar();
A::Bar();
echo self::D;
echo B::D;
new A();
/** @var A */
$a = new A();
new self();
new B();
return $a;
}
@@ -433,12 +433,12 @@ public static function Fedbca(A $a1, ?A $a2, array $a3) : A {
echo A::C;
echo A::C;
self::Blacksheep();
self::Blacksheep();
echo self::D;
B::Blacksheep();
echo B::D;
new A();
/** @var A */
$a = new A();
new self();
new B();
return $a;
}
@@ -515,11 +515,11 @@ public function Fedbca(A $a1, ?A $a2, array $a3) : A {
echo A::C;
$this->Bar();
A::Bar();
echo self::D;
echo AChild::D;
new A();
/** @var A */
$a = new A();
new self();
new AChild();
return $a;
}
@@ -559,7 +559,7 @@ class A {
class B {
public static function bar() : void {
self::Fe();
B::Fe();
}
/**
@@ -598,7 +598,7 @@ public static function Foo() : void {
class B {
public static function bar() : void {
self::Fe();
B::Fe();
}
/**
@@ -652,7 +652,7 @@ class A {
namespace Ns2\Ns3 {
class B {
public static function bar() : void {
self::Fe();
B::Fe();
}
/**
@@ -705,7 +705,7 @@ class A {
class B {
public static function bar() : void {
self::Fedcba();
B::Fedcba();
}
/**

0 comments on commit 2369bac

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