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

✨ Add SlevomatCodingStandard.Functions.StaticClosure #81

Merged
merged 3 commits into from
Jun 4, 2024
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 PreviousNextDrupal/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<!-- SlevomatCodingStandard.Functions -->
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall" />
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration" />
<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />

<!-- SlevomatCodingStandard.Namespaces -->
Expand Down
27 changes: 27 additions & 0 deletions tests/Sniffs/FunctionsStaticClosureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace PreviousNext\CodingStandard\Tests\Sniffs;

/**
* @covers \SlevomatCodingStandard\Sniffs\Functions\StaticClosureSniff
*/
final class FunctionsStaticClosureTest extends Base {

public function testNoError(): void {
$report = self::checkFile(__DIR__ . '/fixtures/FunctionsStaticClosureNoError.php');
self::assertNoSniffErrorInFile($report);
}

public function testError(): void {
$report = self::checkFile(__DIR__ . '/fixtures/FunctionsStaticClosureError.php');
self::assertSame(1, $report->getErrorCount());
self::assertSniffError($report, 16, sniffName: 'SlevomatCodingStandard.Functions.StaticClosure', code: 'ClosureNotStatic');
}

protected static function getSniffName(): string {
return 'SlevomatCodingStandard.Functions.StaticClosure';
}

}
21 changes: 21 additions & 0 deletions tests/Sniffs/fixtures/FunctionsStaticClosureError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace PreviousNext\CodingStandard\Tests\Sniffs\fixtures;

/**
* The class.
*/
final class FunctionsStaticClosureError {

/**
* Foo.
*/
public function foo(): void {
$a = function (): void {
$a = 1;
};
}

}
21 changes: 21 additions & 0 deletions tests/Sniffs/fixtures/FunctionsStaticClosureNoError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Sniffs\fixtures;

/**
* The class.
*/
final class FunctionsStaticClosureNoError {

/**
* Foo.
*/
public function foo(): void {
$a = static function (): void {
$a = 1;
};
}

}
Loading