Skip to content

Commit 3973ee8

Browse files
simPodkukulich
authored andcommitted
Allow suppress for NullableTypeForNullDefaultValue
1 parent fabb4fa commit 3973ee8

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ Sniff provides the following settings:
735735

736736
* `spacesCountBeforeColon`: the number of spaces expected between closing brace and colon.
737737

738-
#### SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue 🔧
738+
#### SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue 🔧🚧
739739

740740
Checks whether the nullablity `?` symbol is present before each nullable and optional parameter (which are marked as `= null`):
741741

SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use SlevomatCodingStandard\Helpers\SuppressHelper;
78
use SlevomatCodingStandard\Helpers\TokenHelper;
89
use function array_key_exists;
910
use function array_merge;
@@ -22,6 +23,8 @@ class NullableTypeForNullDefaultValueSniff implements Sniff
2223

2324
public const CODE_NULLABILITY_SYMBOL_REQUIRED = 'NullabilitySymbolRequired';
2425

26+
private const NAME = 'SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue';
27+
2528
/**
2629
* @return array<int, (int|string)>
2730
*/
@@ -37,6 +40,10 @@ public function register(): array
3740
*/
3841
public function process(File $phpcsFile, $functionPointer): void
3942
{
43+
if (SuppressHelper::isSniffSuppressed($phpcsFile, $functionPointer, self::NAME)) {
44+
return;
45+
}
46+
4047
$tokens = $phpcsFile->getTokens();
4148

4249
$parenthesisOpener = array_key_exists('parenthesis_opener', $tokens[$functionPointer])

tests/Sniffs/TypeHints/data/nullableTypeForNullDefaultValueNoErrors.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public function doFoo(?int $int = null)
2424
class FooBar extends \stdClass
2525
{
2626

27+
/**
28+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
29+
*/
30+
private function isSniffSuppressed(string $a = null)
31+
{
32+
33+
}
34+
2735
public function valid(?bool $bool = null, $noTypehint = null, ?int $int, string $a = 'default', ?string $b = 'null')
2836
{
2937

0 commit comments

Comments
 (0)