Repository: phpactor/phpactor (php)

Issue:
Import all names: `instanceof` names not identified
![image](https://user-images.githubusercontent.com/530801/185990555-644d84d2-5f53-4e0c-8757-7c94cd9741c2.png)


Pull request:
Fix 1856
Fixes #1856 

Patch:
diff --git a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/UnresolvableNameProvider.php b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/UnresolvableNameProvider.php
index 50b04c7c..dead3836 100644
--- a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/UnresolvableNameProvider.php
+++ b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/UnresolvableNameProvider.php
@@ -6,6 +6,7 @@ use Microsoft\PhpParser\Node;
 use Microsoft\PhpParser\Node\Attribute;
 use Microsoft\PhpParser\Node\ClassBaseClause;
 use Microsoft\PhpParser\Node\DelimitedList\QualifiedNameList;
+use Microsoft\PhpParser\Node\Expression\BinaryExpression;
 use Microsoft\PhpParser\Node\MethodDeclaration;
 use Microsoft\PhpParser\Node\Expression\ScopedPropertyAccessExpression;
 use Microsoft\PhpParser\Node\Statement\FunctionDeclaration;
@@ -13,6 +14,7 @@ use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;
 use Microsoft\PhpParser\Node\Expression\CallExpression;
 use Microsoft\PhpParser\Node\QualifiedName;
 use Microsoft\PhpParser\ResolvedName;
+use Microsoft\PhpParser\TokenKind;
 use Phpactor\Name\FullyQualifiedName as PhpactorFullyQualifiedName;
 use Phpactor\TextDocument\ByteOffsetRange;
 use Phpactor\WorseReflection\Bridge\TolerantParser\Patch\TolerantQualifiedNameResolver;
@@ -83,14 +85,16 @@ class UnresolvableNameProvider implements DiagnosticProvider
             return;
         }
 
+        $parent = $name->parent;
         if (
-            !$name->parent instanceof ClassBaseClause &&
-            !$name->parent instanceof QualifiedNameList &&
-            !$name->parent instanceof ObjectCreationExpression &&
-            !$name->parent instanceof ScopedPropertyAccessExpression &&
-            !$name->parent instanceof FunctionDeclaration &&
-            !$name->parent instanceof MethodDeclaration &&
-            !$name->parent instanceof Attribute
+            !$parent instanceof ClassBaseClause &&
+            !$parent instanceof QualifiedNameList &&
+            !$parent instanceof ObjectCreationExpression &&
+            !$parent instanceof ScopedPropertyAccessExpression &&
+            !$parent instanceof FunctionDeclaration &&
+            !$parent instanceof MethodDeclaration &&
+            !$parent instanceof Attribute &&
+            !($parent instanceof BinaryExpression && $parent->operator->kind === TokenKind::InstanceOfKeyword)
         ) {
             return;
         }


Test patch:
diff --git a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/ConstantConcatenation.test b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/ConstantConcatenation.test
new file mode 100644
index 00000000..91e30c91
--- /dev/null
+++ b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/ConstantConcatenation.test
@@ -0,0 +1,3 @@
+<?php
+
+__DIR__ . 'foo';
diff --git a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/UnresolvableInstanceOfClass.test b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/UnresolvableInstanceOfClass.test
new file mode 100644
index 00000000..a2b79826
--- /dev/null
+++ b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProvider/UnresolvableInstanceOfClass.test
@@ -0,0 +1,6 @@
+<?php
+
+namespace Foo;
+
+if ($f instanceof Foobar) {
+}
diff --git a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProviderTest.php b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProviderTest.php
index e1343a55..cbe87868 100644
--- a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProviderTest.php
+++ b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/UnresolvableNameProviderTest.php
@@ -58,6 +58,17 @@ class UnresolvableNameProviderTest extends DiagnosticsTestCase
         self::assertEquals('Class "Foo" not found', $diagnostics->at(0)->message());
     }
 
+    public function checkUnresolvableInstanceOfClass(Diagnostics $diagnostics): void
+    {
+        self::assertCount(1, $diagnostics);
+        self::assertEquals('Class "Foobar" not found', $diagnostics->at(0)->message());
+    }
+
+    public function checkConstantConcatenation(Diagnostics $diagnostics): void
+    {
+        self::assertCount(0, $diagnostics);
+    }
+
     /**
      * @dataProvider provideReturnsUnresolableFunctions
      * @dataProvider provideReturnsUnresolableClass