Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow empty function unless contains a comment #18

Merged
merged 1 commit into from
Nov 3, 2023
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
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