Repository: phpactor/phpactor (php)

Issue:
__destruct() type  declaration
When I have no type declared for __destruct(), phpactor says I should add void return type, but this can't be done, since PHPs definition of __destruct().

Pull request description:
gh-1992: Do not suggest return type for __destruct
Fixes #1992

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad79ffda..5249e6c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ Changelog
 Bug fixes:
 
   - Allow class completion within constant declaration in class #1985 @przepompownia
+  - Do not suggest return type on `__destruct` #1992
+
 
 ## 2022.12.12
 
diff --git a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/MissingReturnTypeProvider.php b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/MissingReturnTypeProvider.php
index 1e259f83..3899c770 100644
--- a/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/MissingReturnTypeProvider.php
+++ b/lib/WorseReflection/Bridge/TolerantParser/Diagnostics/MissingReturnTypeProvider.php
@@ -62,6 +62,10 @@ class MissingReturnTypeProvider implements DiagnosticProvider
             return;
         }
 
+        if ($method->name() === '__destruct') {
+            return;
+        }
+
         if ($method->type()->isDefined()) {
             return;
         }


Test patch:
diff --git a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProvider/MissingReturnTypeConstructDestruct.test b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProvider/MissingReturnTypeConstructDestruct.test
new file mode 100644
index 00000000..12a68adf
--- /dev/null
+++ b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProvider/MissingReturnTypeConstructDestruct.test
@@ -0,0 +1,11 @@
+<?php
+
+class Foobar {
+    public function __construct()
+    {
+    }
+
+    public function __destruct()
+    {
+    }
+}
diff --git a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProviderTest.php b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProviderTest.php
index ae7e068a..94751222 100644
--- a/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProviderTest.php
+++ b/lib/WorseReflection/Tests/Integration/Bridge/TolerantParser/Diagonstics/MissingReturnTypeProviderTest.php
@@ -17,6 +17,11 @@ class MissingReturnTypeProviderTest extends DiagnosticsTestCase
         );
     }
 
+    public function checkMissingReturnTypeConstructDestruct(Diagnostics $diagnostics): void
+    {
+        self::assertCount(0, $diagnostics);
+    }
+
     public function checkMissingReturnTypeWithMissingType(Diagnostics $diagnostics): void
     {
         self::assertCount(1, $diagnostics);