Repository: phpactor/phpactor (php)

Issue:
Completion of virtual methods on the Faker\Generator class doesn't seem to work.
I am trying to use `phpactor` with Emacs + `eglot`, inside a Laravel project.
I try to use the virtual methods on the Faker\Generator class through the `fake()` helper method, which essentially returns a `Faker\Generator` instance.

The issue is that the completions shows the various generators as `property`, rather than `methods`, and `FakerPHP` has deprecated the `property` syntax. Additionally, if I type the method out myself, it shows warnings that the method does not exist.

This is on Laravel 10, with Emacs 29 and PHP 8.2.3

![image](https://user-images.githubusercontent.com/56113511/220097012-225a51fa-2d89-41c6-b16a-d58a028c4947.png)
![image](https://user-images.githubusercontent.com/56113511/220097025-c30a80f4-4bed-4896-820f-14475ba2943e.png)

Pull request description:
Gh 2108: Fix virtual members with same name replacing eachother
fixes #2108 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3fcf72b9..b202f57b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ Changelog
 
 Bug fixes:
 
+  - Fix different virtual member types with the same name replacing eachother #2108
   - Specify maximimum size (255 chars) for string literal types #2144
   - Fix docblock parser with `$this` when used as generic argument #2092
 
diff --git a/lib/WorseReflection/Core/Virtual/ChainReflectionMemberProvider.php b/lib/WorseReflection/Core/Virtual/ChainReflectionMemberProvider.php
index 99ea4196..6af3584e 100644
--- a/lib/WorseReflection/Core/Virtual/ChainReflectionMemberProvider.php
+++ b/lib/WorseReflection/Core/Virtual/ChainReflectionMemberProvider.php
@@ -2,7 +2,7 @@
 
 namespace Phpactor\WorseReflection\Core\Virtual;
 
-use Phpactor\WorseReflection\Core\Reflection\Collection\HomogeneousReflectionMemberCollection;
+use Phpactor\WorseReflection\Core\Reflection\Collection\ClassLikeReflectionMemberCollection;
 use Phpactor\WorseReflection\Core\Reflection\Collection\ReflectionMemberCollection;
 use Phpactor\WorseReflection\Core\Reflection\ReflectionClassLike;
 use Phpactor\WorseReflection\Core\ServiceLocator;
@@ -23,7 +23,7 @@ class ChainReflectionMemberProvider implements ReflectionMemberProvider
 
     public function provideMembers(ServiceLocator $locator, ReflectionClassLike $class): ReflectionMemberCollection
     {
-        $virtualMethods = HomogeneousReflectionMemberCollection::empty();
+        $virtualMethods = ClassLikeReflectionMemberCollection::empty();
         foreach ($this->providers as $provider) {
             /** @phpstan-ignore-next-line */
             $virtualMethods = $virtualMethods->merge($provider->provideMembers($locator, $class));


Test patch:
diff --git a/lib/WorseReflection/Tests/Inference/virtual_member/method_and_property_with_same_name.test b/lib/WorseReflection/Tests/Inference/virtual_member/method_and_property_with_same_name.test
new file mode 100644
index 00000000..a62c2f99
--- /dev/null
+++ b/lib/WorseReflection/Tests/Inference/virtual_member/method_and_property_with_same_name.test
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * @method int foo()
+ * @property string $foo
+ */
+class A {}
+
+$a = new A();
+wrAssertType('int', $a->foo());