Skip to content

Commit

Permalink
Allow suppress for NullableTypeForNullDefaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored and kukulich committed Jan 23, 2020
1 parent fabb4fa commit 3973ee8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ Sniff provides the following settings:

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

#### SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue 🔧
#### SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue 🔧🚧

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use SlevomatCodingStandard\Helpers\SuppressHelper;
use SlevomatCodingStandard\Helpers\TokenHelper;
use function array_key_exists;
use function array_merge;
Expand All @@ -22,6 +23,8 @@ class NullableTypeForNullDefaultValueSniff implements Sniff

public const CODE_NULLABILITY_SYMBOL_REQUIRED = 'NullabilitySymbolRequired';

private const NAME = 'SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue';

/**
* @return array<int, (int|string)>
*/
Expand All @@ -37,6 +40,10 @@ public function register(): array
*/
public function process(File $phpcsFile, $functionPointer): void
{
if (SuppressHelper::isSniffSuppressed($phpcsFile, $functionPointer, self::NAME)) {
return;
}

$tokens = $phpcsFile->getTokens();

$parenthesisOpener = array_key_exists('parenthesis_opener', $tokens[$functionPointer])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function doFoo(?int $int = null)
class FooBar extends \stdClass
{

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
*/
private function isSniffSuppressed(string $a = null)
{

}

public function valid(?bool $bool = null, $noTypehint = null, ?int $int, string $a = 'default', ?string $b = 'null')
{

Expand Down

0 comments on commit 3973ee8

Please sign in to comment.