Skip to content

Commit 2aaf695

Browse files
authored
✨ Add SlevomatCodingStandard.TypeHints.DeclareStrictTypes (#9)
1 parent cda9e39 commit 2aaf695

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

PreviousNextDrupal/ruleset.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
<!-- SlevomatCodingStandard.Namespaces -->
3232
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
3333

34+
<!-- SlevomatCodingStandard.TypeHints -->
35+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
36+
<properties>
37+
<property name="spacesCountAroundEqualsSign" type="int" value="1" />
38+
</properties>
39+
</rule>
40+
3441
<!-- Drupal -->
3542
<rule ref="Drupal" />
3643

tests/Sniffs/StrictTypesTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace PreviousNext\CodingStandard\Tests\Sniffs;
6+
7+
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
8+
9+
/**
10+
* @covers \SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff
11+
*/
12+
final class StrictTypesTest extends Base {
13+
14+
public function testNoError(): void {
15+
$report = self::checkFile(__DIR__ . '/fixtures/StrictTypesNoError.php');
16+
self::assertNoSniffErrorInFile($report);
17+
}
18+
19+
public function testMissing(): void {
20+
$report = self::checkFile(__DIR__ . '/fixtures/StrictTypesMissing.php');
21+
self::assertSame(1, $report->getErrorCount());
22+
self::assertSniffError($report, 1, DeclareStrictTypesSniff::CODE_DECLARE_STRICT_TYPES_MISSING);
23+
}
24+
25+
public function testSpacing(): void {
26+
$report = self::checkFile(__DIR__ . '/fixtures/StrictTypesSpacing.php');
27+
self::assertSame(1, $report->getErrorCount());
28+
self::assertSniffError($report, 3, DeclareStrictTypesSniff::CODE_INCORRECT_STRICT_TYPES_FORMAT);
29+
}
30+
31+
protected static function getSniffName(): string {
32+
return 'SlevomatCodingStandard.TypeHints.DeclareStrictTypes';
33+
}
34+
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
declare(strict_types = 1);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
declare(strict_types=1);

0 commit comments

Comments
 (0)