diff --git a/docs/assets/no-violation.svg b/docs/assets/no-violation.svg
index f6274a60..6424347f 100644
--- a/docs/assets/no-violation.svg
+++ b/docs/assets/no-violation.svg
@@ -14,7 +14,7 @@
➜ prj-ddd vendor/bin/structarmed analyze
-
+
===============================================
diff --git a/docs/assets/structarmed-showoff.svg b/docs/assets/structarmed-showoff.svg
index 7ffbd72b..9357c82c 100644
--- a/docs/assets/structarmed-showoff.svg
+++ b/docs/assets/structarmed-showoff.svg
@@ -15,7 +15,7 @@
➜ prj-ddd vendor/bin/structarmed analyze
-
+
===============================================
diff --git a/src/Analyser/MethodNode.php b/src/Analyser/MethodNode.php
index de5e8f57..c4dcbda0 100644
--- a/src/Analyser/MethodNode.php
+++ b/src/Analyser/MethodNode.php
@@ -28,4 +28,9 @@ public function isConstructor(): bool
{
return $this->name === '__construct';
}
+
+ public function isDestructor(): bool
+ {
+ return $this->name === '__destruct';
+ }
}
diff --git a/src/Rule/Rules/Method/MustHaveReturnTypeRule.php b/src/Rule/Rules/Method/MustHaveReturnTypeRule.php
index 30b73294..a7f48fd1 100644
--- a/src/Rule/Rules/Method/MustHaveReturnTypeRule.php
+++ b/src/Rule/Rules/Method/MustHaveReturnTypeRule.php
@@ -45,7 +45,11 @@ public function evaluateAll(ClassNode $classNode): array
$violations = [];
foreach ($classNode->methods as $method) {
- if (! $method->isPublic() || $method->isConstructor()) {
+ if (
+ ! $method->isPublic()
+ || $method->isConstructor()
+ || $method->isDestructor()
+ ) {
continue;
}
diff --git a/tests/Analyser/MethodNodeTest.php b/tests/Analyser/MethodNodeTest.php
index cb55e05d..200980fd 100644
--- a/tests/Analyser/MethodNodeTest.php
+++ b/tests/Analyser/MethodNodeTest.php
@@ -14,11 +14,15 @@ final class MethodNodeTest extends TestCase
public function testMethodHelpers(): void
{
$publicConstructor = new MethodNode('__construct', 'public', false, false, 1, 1, 3);
+ $publicDestructor = new MethodNode('__destruct', 'public', false, false, 0, 1, 3);
$protectedMethod = new MethodNode('handle', 'protected', true, false, 0, 1, 2);
$this->assertTrue($publicConstructor->isPublic());
$this->assertTrue($publicConstructor->isConstructor());
+ $this->assertFalse($publicConstructor->isDestructor());
+ $this->assertTrue($publicDestructor->isDestructor());
$this->assertFalse($protectedMethod->isPublic());
$this->assertFalse($protectedMethod->isConstructor());
+ $this->assertFalse($protectedMethod->isDestructor());
}
}
diff --git a/tests/Rule/Method/MustHaveReturnTypeRuleTest.php b/tests/Rule/Method/MustHaveReturnTypeRuleTest.php
index b4d742de..8174f79c 100644
--- a/tests/Rule/Method/MustHaveReturnTypeRuleTest.php
+++ b/tests/Rule/Method/MustHaveReturnTypeRuleTest.php
@@ -82,6 +82,16 @@ public function testIgnoresConstructor(): void
$this->assertNotInstanceOf(RuleViolation::class, $mustHaveReturnTypeRule->evaluate($classNode));
}
+ public function testIgnoresDestructor(): void
+ {
+ $mustHaveReturnTypeRule = new MustHaveReturnTypeRule(layer: 'Domain');
+ $classNode = $this->makeNode([
+ $this->method('__destruct', hasReturnType: false),
+ ]);
+
+ $this->assertNotInstanceOf(RuleViolation::class, $mustHaveReturnTypeRule->evaluate($classNode));
+ }
+
public function testIgnoresPrivateMethods(): void
{
$mustHaveReturnTypeRule = new MustHaveReturnTypeRule(layer: 'Domain');