Skip to content

Commit cca85bb

Browse files
authored
✨ Add SlevomatCodingStandard.Functions.StaticClosure (#81)
1 parent 742c11a commit cca85bb

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

PreviousNextDrupal/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<!-- SlevomatCodingStandard.Functions -->
3737
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall" />
3838
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration" />
39+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure" />
3940
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
4041

4142
<!-- SlevomatCodingStandard.Namespaces -->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PreviousNext\CodingStandard\Tests\Sniffs;
6+
7+
/**
8+
* @covers \SlevomatCodingStandard\Sniffs\Functions\StaticClosureSniff
9+
*/
10+
final class FunctionsStaticClosureTest extends Base {
11+
12+
public function testNoError(): void {
13+
$report = self::checkFile(__DIR__ . '/fixtures/FunctionsStaticClosureNoError.php');
14+
self::assertNoSniffErrorInFile($report);
15+
}
16+
17+
public function testError(): void {
18+
$report = self::checkFile(__DIR__ . '/fixtures/FunctionsStaticClosureError.php');
19+
self::assertSame(1, $report->getErrorCount());
20+
self::assertSniffError($report, 16, sniffName: 'SlevomatCodingStandard.Functions.StaticClosure', code: 'ClosureNotStatic');
21+
}
22+
23+
protected static function getSniffName(): string {
24+
return 'SlevomatCodingStandard.Functions.StaticClosure';
25+
}
26+
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PreviousNext\CodingStandard\Tests\Sniffs\fixtures;
6+
7+
/**
8+
* The class.
9+
*/
10+
final class FunctionsStaticClosureError {
11+
12+
/**
13+
* Foo.
14+
*/
15+
public function foo(): void {
16+
$a = function (): void {
17+
$a = 1;
18+
};
19+
}
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sniffs\fixtures;
6+
7+
/**
8+
* The class.
9+
*/
10+
final class FunctionsStaticClosureNoError {
11+
12+
/**
13+
* Foo.
14+
*/
15+
public function foo(): void {
16+
$a = static function (): void {
17+
$a = 1;
18+
};
19+
}
20+
21+
}

0 commit comments

Comments
 (0)