Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/assets/no-violation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/assets/structarmed-showoff.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/Analyser/MethodNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function isConstructor(): bool
{
return $this->name === '__construct';
}

public function isDestructor(): bool
{
return $this->name === '__destruct';
}
}
6 changes: 5 additions & 1 deletion src/Rule/Rules/Method/MustHaveReturnTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Analyser/MethodNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
10 changes: 10 additions & 0 deletions tests/Rule/Method/MustHaveReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading