Skip to content

Commit

Permalink
Disallow empty function unless adding a comment (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
asispts committed Nov 3, 2023
1 parent 9f0c019 commit c7f260e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions ptscs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<rule ref="SlevomatCodingStandard.Variables.UselessVariable" />
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" />
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction" />
<rule ref="SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment" />
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment" />

Expand Down
1 change: 1 addition & 0 deletions tests/Sniffs/CodeAnalysis/UnnecessaryFinalModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function setUp(): void
'Squiz.Classes.ClassFileName.NoMatch',
'PSR1.Classes.ClassDeclaration.MultipleClasses',
'SlevomatCodingStandard.Classes.RequireAbstractOrFinal',
'SlevomatCodingStandard.Functions.DisallowEmptyFunction',
]);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/Sniffs/Slevomat/Functions/DisallowEmptyFunctionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace Ptscs\Tests\Sniffs\Slevomat\Functions;

use Iterator;
use Ptscs\Tests\SniffTestCase;
use Ptscs\Tests\Utils\ErrorData;

final class DisallowEmptyFunctionTest extends SniffTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch');
}

public static function provideTestData(): Iterator
{
yield[
[new ErrorData(3, 'SlevomatCodingStandard.Functions.DisallowEmptyFunction.EmptyFunction')],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function emptyFunction()
{
}

function allowed()
{
// allowed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

function emptyFunction()
{
}

function allowed()
{
// allowed
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ final class Foobar
{
public function check(string $useless, array $list, $missing): void
{
// empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ final class Foobar
*/
public function check(string $useless, array $list, $missing): void
{
// empty
}
}
5 changes: 4 additions & 1 deletion tests/Sniffs/Slevomat/UnusedUseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ final class UnusedUseTest extends SniffTestCase
protected function setUp(): void
{
parent::setUp();
$this->setExclude(['Squiz.Classes.ClassFileName.NoMatch']);
$this->setExclude([
'Squiz.Classes.ClassFileName.NoMatch',
'SlevomatCodingStandard.Functions.DisallowEmptyFunction',
]);
}

public static function provideTestData(): Iterator
Expand Down
1 change: 1 addition & 0 deletions tests/Sniffs/Squiz/ClassMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected function setUp(): void
$this->appendExclude('Squiz.Classes.ClassFileName');
$this->appendExclude('Generic.PHP.RequireStrictTypes.MissingDeclaration');
$this->appendExclude('SlevomatCodingStandard.Classes.RequireAbstractOrFinal');
$this->appendExclude('SlevomatCodingStandard.Functions.DisallowEmptyFunction');
}

public static function provideTestData(): Iterator
Expand Down
1 change: 1 addition & 0 deletions tests/Sniffs/Squiz/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class FunctionsTest extends SniffTestCase
protected function setUp(): void
{
$this->appendExclude('PSR1.Files.SideEffects.FoundWithSymbols');
$this->appendExclude('SlevomatCodingStandard.Functions.DisallowEmptyFunction');
}

public static function provideTestData(): Iterator
Expand Down

0 comments on commit c7f260e

Please sign in to comment.