Skip to content

Commit 61e439e

Browse files
committed
Enable PHP 7.4+ sniffs always
1 parent 54a7545 commit 61e439e

15 files changed

+12
-217
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/RequireNullCoalesceEqualOperatorSniff.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHP_CodeSniffer\Util\Tokens;
88
use SlevomatCodingStandard\Helpers\FixerHelper;
99
use SlevomatCodingStandard\Helpers\IdentificatorHelper;
10-
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
1110
use SlevomatCodingStandard\Helpers\TokenHelper;
1211
use const T_COALESCE;
1312
use const T_EQUAL;
@@ -18,7 +17,8 @@ class RequireNullCoalesceEqualOperatorSniff implements Sniff
1817

1918
public const CODE_REQUIRED_NULL_COALESCE_EQUAL_OPERATOR = 'RequiredNullCoalesceEqualOperator';
2019

21-
public ?bool $enable = null;
20+
/** @deprecated */
21+
public bool $enable = true;
2222

2323
/**
2424
* @return array<int, (int|string)>
@@ -36,12 +36,6 @@ public function register(): array
3636
*/
3737
public function process(File $phpcsFile, $equalPointer): void
3838
{
39-
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 70400);
40-
41-
if (!$this->enable) {
42-
return;
43-
}
44-
4539
/** @var int $variableStartPointer */
4640
$variableStartPointer = TokenHelper::findNextEffective($phpcsFile, $equalPointer + 1);
4741
$variableEndPointer = IdentificatorHelper::findEndPointer($phpcsFile, $variableStartPointer);

SlevomatCodingStandard/Sniffs/Functions/RequireArrowFunctionSniff.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77
use SlevomatCodingStandard\Helpers\FixerHelper;
88
use SlevomatCodingStandard\Helpers\ScopeHelper;
9-
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
109
use SlevomatCodingStandard\Helpers\TokenHelper;
1110
use function count;
1211
use const T_BITWISE_AND;
@@ -25,7 +24,8 @@ class RequireArrowFunctionSniff implements Sniff
2524

2625
public bool $allowNested = true;
2726

28-
public ?bool $enable = null;
27+
/** @deprecated */
28+
public bool $enable = true;
2929

3030
/**
3131
* @return array<int, (int|string)>
@@ -43,12 +43,6 @@ public function register(): array
4343
*/
4444
public function process(File $phpcsFile, $closurePointer): void
4545
{
46-
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 70400);
47-
48-
if (!$this->enable) {
49-
return;
50-
}
51-
5246
$tokens = $phpcsFile->getTokens();
5347

5448
$returnPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$closurePointer]['scope_opener'] + 1);

SlevomatCodingStandard/Sniffs/Numbers/RequireNumericLiteralSeparatorSniff.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class RequireNumericLiteralSeparatorSniff implements Sniff
1515

1616
public const CODE_REQUIRED_NUMERIC_LITERAL_SEPARATOR = 'RequiredNumericLiteralSeparator';
1717

18-
public ?bool $enable = null;
18+
/** @deprecated */
19+
public bool $enable = true;
1920

2021
public int $minDigitsBeforeDecimalPoint = 4;
2122

@@ -40,14 +41,9 @@ public function register(): array
4041
*/
4142
public function process(File $phpcsFile, $numberPointer): void
4243
{
43-
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 70400);
4444
$this->minDigitsBeforeDecimalPoint = SniffSettingsHelper::normalizeInteger($this->minDigitsBeforeDecimalPoint);
4545
$this->minDigitsAfterDecimalPoint = SniffSettingsHelper::normalizeInteger($this->minDigitsAfterDecimalPoint);
4646

47-
if (!$this->enable) {
48-
return;
49-
}
50-
5147
$tokens = $phpcsFile->getTokens();
5248
$number = $tokens[$numberPointer]['content'];
5349

SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class PropertyTypeHintSniff implements Sniff
6868

6969
private const NAME = 'SlevomatCodingStandard.TypeHints.PropertyTypeHint';
7070

71-
public ?bool $enableNativeTypeHint = null;
71+
/** @deprecated */
72+
public bool $enableNativeTypeHint = true;
7273

7374
public ?bool $enableMixedTypeHint = null;
7475

@@ -104,7 +105,6 @@ public function register(): array
104105
*/
105106
public function process(File $phpcsFile, $pointer): void
106107
{
107-
$this->enableNativeTypeHint = SniffSettingsHelper::isEnabledByPhpVersion($this->enableNativeTypeHint, 70400);
108108
$this->enableMixedTypeHint = $this->enableNativeTypeHint
109109
? SniffSettingsHelper::isEnabledByPhpVersion($this->enableMixedTypeHint, 80000)
110110
: false;

doc/control-structures.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ Sniff provides the following settings:
191191

192192
Requires use of null coalesce equal operator when possible.
193193

194-
This sniff provides the following setting:
195-
196-
* `enable`: either to enable or not this sniff. By default, it is enabled for PHP versions 7.4 or higher.
197-
198194
#### SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator 🔧
199195

200196
Requires use of null coalesce operator when possible.

doc/functions.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Requires arrow functions.
3434
Sniff provides the following settings:
3535

3636
* `allowNested` (default: `true`)
37-
* `enable`: either to enable or not this sniff. By default, it is enabled for PHP versions 7.4 or higher.
3837

3938
#### SlevomatCodingStandard.Functions.RequireMultiLineCall 🔧
4039

doc/numbers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Requires use of numeric literal separators.
1010

1111
This sniff provides the following setting:
1212

13-
* `enable`: either to enable or not this sniff. By default, it is enabled for PHP versions 7.4 or higher.
1413
* `minDigitsBeforeDecimalPoint`: the minimum digits before decimal point to require separator.
1514
* `minDigitsAfterDecimalPoint`: the minimum digits after decimal point to require separator.
1615
* `ignoreOctalNumbers`: to ignore octal numbers.

doc/type-hints.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ This sniff can cause an error if you're overriding or implementing a parent meth
8383

8484
Sniff provides the following settings:
8585

86-
* `enableNativeTypeHint`: enforces to transform `@var int` into native `int` typehint. It's on by default if you're on PHP 7.4+
8786
* `enableMixedTypeHint`: enforces to transform `@var mixed` into native `mixed` typehint. It's on by default if you're on PHP 8.0+. It can be enabled only when `enableNativeTypeHint` is enabled too.
8887
* `enableUnionTypeHint`: enforces to transform `@var string|int` into native `string|int` typehint. It's on by default if you're on PHP 8.0+. It can be enabled only when `enableNativeTypeHint` is enabled too.
8988
* `enableIntersectionTypeHint`: enforces to transform `@var Foo&Bar` into native `Foo&Bar` typehint. It's on by default if you're on PHP 8.1+. It can be enabled only when `enableNativeTypeHint` is enabled too.

tests/Sniffs/ControlStructures/RequireNullCoalesceEqualOperatorSniffTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ class RequireNullCoalesceEqualOperatorSniffTest extends TestCase
99

1010
public function testNoErrors(): void
1111
{
12-
$report = self::checkFile(__DIR__ . '/data/requireNullCoalesceEqualOperatorNoErrors.php', [
13-
'enable' => true,
14-
]);
12+
$report = self::checkFile(__DIR__ . '/data/requireNullCoalesceEqualOperatorNoErrors.php');
1513
self::assertNoSniffErrorInFile($report);
1614
}
1715

1816
public function testErrors(): void
1917
{
2018
$report = self::checkFile(
2119
__DIR__ . '/data/requireNullCoalesceEqualOperatorErrors.php',
22-
['enable' => true],
20+
[],
2321
[RequireNullCoalesceEqualOperatorSniff::CODE_REQUIRED_NULL_COALESCE_EQUAL_OPERATOR],
2422
);
2523

@@ -32,15 +30,4 @@ public function testErrors(): void
3230
self::assertAllFixedInFile($report);
3331
}
3432

35-
public function testShouldNotReportIfSniffIsDisabled(): void
36-
{
37-
$report = self::checkFile(
38-
__DIR__ . '/data/requireNullCoalesceEqualOperatorErrors.php',
39-
['enable' => false],
40-
[RequireNullCoalesceEqualOperatorSniff::CODE_REQUIRED_NULL_COALESCE_EQUAL_OPERATOR],
41-
);
42-
43-
self::assertNoSniffErrorInFile($report);
44-
}
45-
4633
}

tests/Sniffs/Functions/RequireArrowFunctionSniffTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public function testDisallowNestedNoErrors(): void
1111
{
1212
$report = self::checkFile(__DIR__ . '/data/requireArrowFunctionDisallowNestedNoErrors.php', [
1313
'allowNested' => false,
14-
'enable' => true,
1514
]);
1615
self::assertNoSniffErrorInFile($report);
1716
}
@@ -20,7 +19,6 @@ public function testDisallowNestedErrors(): void
2019
{
2120
$report = self::checkFile(__DIR__ . '/data/requireArrowFunctionDisallowNestedErrors.php', [
2221
'allowNested' => false,
23-
'enable' => true,
2422
]);
2523

2624
self::assertSame(4, $report->getErrorCount());
@@ -37,7 +35,6 @@ public function testAllowNestedNoErrors(): void
3735
{
3836
$report = self::checkFile(__DIR__ . '/data/requireArrowFunctionAllowNestedNoErrors.php', [
3937
'allowNested' => true,
40-
'enable' => true,
4138
]);
4239
self::assertNoSniffErrorInFile($report);
4340
}
@@ -46,7 +43,6 @@ public function testAllowNestedErrors(): void
4643
{
4744
$report = self::checkFile(__DIR__ . '/data/requireArrowFunctionAllowNestedErrors.php', [
4845
'allowNested' => true,
49-
'enable' => true,
5046
]);
5147

5248
self::assertSame(3, $report->getErrorCount());
@@ -58,14 +54,4 @@ public function testAllowNestedErrors(): void
5854
self::assertAllFixedInFile($report);
5955
}
6056

61-
public function testShouldNotReportIfSniffIsDisabled(): void
62-
{
63-
$report = self::checkFile(__DIR__ . '/data/requireArrowFunctionAllowNestedErrors.php', [
64-
'allowNested' => true,
65-
'enable' => false,
66-
]);
67-
68-
self::assertNoSniffErrorInFile($report);
69-
}
70-
7157
}

tests/Sniffs/Numbers/RequireNumericLiteralSeparatorSniffTest.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ class RequireNumericLiteralSeparatorSniffTest extends TestCase
99

1010
public function testNoErrors(): void
1111
{
12-
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorNoErrors.php', [
13-
'enable' => true,
14-
]);
12+
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorNoErrors.php');
1513
self::assertNoSniffErrorInFile($report);
1614
}
1715

1816
public function testErrors(): void
1917
{
20-
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorErrors.php', [
21-
'enable' => true,
22-
]);
18+
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorErrors.php');
2319

2420
self::assertSame(4, $report->getErrorCount());
2521

@@ -32,7 +28,6 @@ public function testErrors(): void
3228
public function testModifiedSettingsNoErrors(): void
3329
{
3430
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorModifiedSettingsNoErrors.php', [
35-
'enable' => true,
3631
'minDigitsBeforeDecimalPoint' => 7,
3732
'minDigitsAfterDecimalPoint' => 6,
3833
'ignoreOctalNumbers' => false,
@@ -43,7 +38,6 @@ public function testModifiedSettingsNoErrors(): void
4338
public function testModifiedSettingsErrors(): void
4439
{
4540
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorModifiedSettingsErrors.php', [
46-
'enable' => true,
4741
'minDigitsBeforeDecimalPoint' => 7,
4842
'minDigitsAfterDecimalPoint' => 6,
4943
'ignoreOctalNumbers' => false,
@@ -56,13 +50,4 @@ public function testModifiedSettingsErrors(): void
5650
self::assertSniffError($report, 5, RequireNumericLiteralSeparatorSniff::CODE_REQUIRED_NUMERIC_LITERAL_SEPARATOR);
5751
}
5852

59-
public function testShouldNotReportIfSniffIsDisabled(): void
60-
{
61-
$report = self::checkFile(__DIR__ . '/data/requireNumericLiteralSeparatorErrors.php', [
62-
'enable' => false,
63-
]);
64-
65-
self::assertNoSniffErrorInFile($report);
66-
}
67-
6853
}

tests/Sniffs/TypeHints/PropertyTypeHintSniffTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,9 @@
77
class PropertyTypeHintSniffTest extends TestCase
88
{
99

10-
public function testDisabledNativeNoErrors(): void
11-
{
12-
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintDisabledNativeNoErrors.php', [
13-
'enableNativeTypeHint' => false,
14-
]);
15-
self::assertNoSniffErrorInFile($report);
16-
}
17-
18-
public function testDisabledNativeErrors(): void
19-
{
20-
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintDisabledNativeErrors.php', [
21-
'enableNativeTypeHint' => false,
22-
'traversableTypeHints' => ['Traversable', '\ArrayIterator'],
23-
]);
24-
25-
self::assertSame(5, $report->getErrorCount());
26-
27-
self::assertSniffError($report, 9, PropertyTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT);
28-
self::assertSniffError($report, 11, PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
29-
self::assertSniffError($report, 14, PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
30-
self::assertSniffError($report, 17, PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION);
31-
self::assertSniffError($report, 23, PropertyTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT);
32-
33-
self::assertAllFixedInFile($report);
34-
}
35-
3610
public function testEnabledNativeNoErrors(): void
3711
{
3812
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeNoErrors.php', [
39-
'enableNativeTypeHint' => true,
4013
'enableMixedTypeHint' => true,
4114
'enableUnionTypeHint' => false,
4215
'enableIntersectionTypeHint' => false,
@@ -49,7 +22,6 @@ public function testEnabledNativeNoErrors(): void
4922
public function testEnabledNativeErrors(): void
5023
{
5124
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeErrors.php', [
52-
'enableNativeTypeHint' => true,
5325
'enableMixedTypeHint' => true,
5426
'enableUnionTypeHint' => false,
5527
'enableIntersectionTypeHint' => false,
@@ -120,7 +92,6 @@ public function testEnabledNativeErrors(): void
12092
public function testEnabledNativeWithUnionNoErrors(): void
12193
{
12294
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeWithUnionNoErrors.php', [
123-
'enableNativeTypeHint' => true,
12495
'enableMixedTypeHint' => true,
12596
'enableUnionTypeHint' => true,
12697
'enableIntersectionTypeHint' => false,
@@ -133,7 +104,6 @@ public function testEnabledNativeWithUnionNoErrors(): void
133104
public function testEnabledNativeWithUnionErrors(): void
134105
{
135106
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeWithUnionErrors.php', [
136-
'enableNativeTypeHint' => true,
137107
'enableMixedTypeHint' => true,
138108
'enableUnionTypeHint' => true,
139109
'enableIntersectionTypeHint' => false,
@@ -163,7 +133,6 @@ public function testEnabledNativeWithUnionErrors(): void
163133
public function testEnabledNativeWithIntersectionNoErrors(): void
164134
{
165135
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeWithIntersectionNoErrors.php', [
166-
'enableNativeTypeHint' => true,
167136
'enableMixedTypeHint' => true,
168137
'enableUnionTypeHint' => false,
169138
'enableIntersectionTypeHint' => true,
@@ -176,7 +145,6 @@ public function testEnabledNativeWithIntersectionNoErrors(): void
176145
public function testEnabledNativeWithIntersectionErrors(): void
177146
{
178147
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintEnabledNativeWithIntersectionErrors.php', [
179-
'enableNativeTypeHint' => true,
180148
'enableMixedTypeHint' => true,
181149
'enableUnionTypeHint' => false,
182150
'enableIntersectionTypeHint' => true,
@@ -195,7 +163,6 @@ public function testEnabledNativeWithIntersectionErrors(): void
195163
public function testWithNullTrueFalseErrors(): void
196164
{
197165
$report = self::checkFile(__DIR__ . '/data/propertyTypeHintWithNullTrueFalseErrors.php', [
198-
'enableNativeTypeHint' => true,
199166
'enableMixedTypeHint' => true,
200167
'enableUnionTypeHint' => true,
201168
'enableIntersectionTypeHint' => true,

tests/Sniffs/TypeHints/data/propertyTypeHintDisabledNativeErrors.fixed.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)