Skip to content

Commit 09f6a88

Browse files
VasekPurchartkukulich
authored andcommitted
Autodisable PHP 7.1 only sniffs
1 parent 282febc commit 09f6a88

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

SlevomatCodingStandard/Sniffs/Classes/ClassConstantVisibilitySniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ class ClassConstantVisibilitySniff implements \PHP_CodeSniffer_Sniff
1010

1111
const CODE_MISSING_CONSTANT_VISIBILITY = 'MissingConstantVisibility';
1212

13+
/**
14+
* Automatically disables the sniff on unusable version, to be removed when only PHP 7.1+ is supported
15+
*
16+
* @var bool
17+
*/
18+
public $enabled = PHP_VERSION_ID >= 70100;
19+
1320
/**
1421
* @return int[]
1522
*/
1623
public function register(): array
1724
{
25+
if (!$this->enabled) {
26+
return [];
27+
}
28+
1829
return [
1930
T_CONST,
2031
];

SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ class NullableTypeForNullDefaultValueSniff implements \PHP_CodeSniffer_Sniff
99

1010
const CODE_NULLABILITY_SYMBOL_REQUIRED = 'NullabilitySymbolRequired';
1111

12+
/**
13+
* Automatically disables the sniff on unusable version, to be removed when only PHP 7.1+ is supported
14+
*
15+
* @var bool
16+
*/
17+
public $enabled = PHP_VERSION_ID >= 70100;
18+
1219
/**
1320
* @return int[]
1421
*/
1522
public function register(): array
1623
{
24+
if (!$this->enabled) {
25+
return [];
26+
}
27+
1728
return [
1829
T_FUNCTION,
1930
T_CLOSURE,

tests/Sniffs/Classes/ClassConstantVisibilitySniffTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class ClassConstantVisibilitySniffTest extends \SlevomatCodingStandard\Sniffs\Te
77

88
public function testErrors()
99
{
10-
$report = $this->checkFile(__DIR__ . '/data/classWithConstants.php');
10+
$report = $this->checkFile(__DIR__ . '/data/classWithConstants.php', [
11+
'enabled' => true,
12+
]);
1113

1214
$this->assertSame(1, $report->getErrorCount());
1315

@@ -25,13 +27,25 @@ public function testErrors()
2527

2628
public function testNoClassConstants()
2729
{
28-
$report = $this->checkFile(__DIR__ . '/data/noClassConstants.php');
30+
$report = $this->checkFile(__DIR__ . '/data/noClassConstants.php', [
31+
'enabled' => true,
32+
]);
2933
$this->assertNoSniffErrorInFile($report);
3034
}
3135

3236
public function testNoClassConstantsWithNamespace()
3337
{
34-
$report = $this->checkFile(__DIR__ . '/data/noClassConstantsWithNamespace.php');
38+
$report = $this->checkFile(__DIR__ . '/data/noClassConstantsWithNamespace.php', [
39+
'enabled' => true,
40+
]);
41+
$this->assertNoSniffErrorInFile($report);
42+
}
43+
44+
public function testDisabledSniff()
45+
{
46+
$report = $this->checkFile(__DIR__ . '/data/classWithConstants.php', [
47+
'enabled' => false,
48+
]);
3549
$this->assertNoSniffErrorInFile($report);
3650
}
3751

tests/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniffTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ class NullableTypeForNullDefaultValueSniffTest extends \SlevomatCodingStandard\S
77

88
public function testNoErrors()
99
{
10-
$this->assertNoSniffErrorInFile($this->checkFile(__DIR__ . '/data/nullableTypeForNullDefaultValueNoErrors.php'));
10+
$this->assertNoSniffErrorInFile($this->checkFile(__DIR__ . '/data/nullableTypeForNullDefaultValueNoErrors.php', [
11+
'enabled' => true,
12+
]));
1113
}
1214

1315
public function testErrors()
1416
{
15-
$report = $this->checkFile(__DIR__ . '/data/nullableTypeForNullDefaultValueErrors.php');
17+
$report = $this->checkFile(__DIR__ . '/data/nullableTypeForNullDefaultValueErrors.php', [
18+
'enabled' => true,
19+
]);
1620

1721
$this->assertSame(11, $report->getErrorCount());
1822

@@ -33,8 +37,18 @@ public function testErrors()
3337
public function testFixable()
3438
{
3539
$codes = [NullableTypeForNullDefaultValueSniff::CODE_NULLABILITY_SYMBOL_REQUIRED];
36-
$report = $this->checkFile(__DIR__ . '/data/fixableNullableTypeForNullDefaultValue.php', [], $codes);
40+
$report = $this->checkFile(__DIR__ . '/data/fixableNullableTypeForNullDefaultValue.php', [
41+
'enabled' => true,
42+
], $codes);
3743
$this->assertAllFixedInFile($report);
3844
}
3945

46+
public function testDisabledSniff()
47+
{
48+
$report = $this->checkFile(__DIR__ . '/data/nullableTypeForNullDefaultValueErrors.php', [
49+
'enabled' => false,
50+
]);
51+
$this->assertNoSniffErrorInFile($report);
52+
}
53+
4054
}

0 commit comments

Comments
 (0)