diff --git a/SlevomatCodingStandard/Sniffs/TypeHints/DNFTypeHintFormatSniff.php b/SlevomatCodingStandard/Sniffs/TypeHints/DNFTypeHintFormatSniff.php index 78341ea0c..bf8882578 100644 --- a/SlevomatCodingStandard/Sniffs/TypeHints/DNFTypeHintFormatSniff.php +++ b/SlevomatCodingStandard/Sniffs/TypeHints/DNFTypeHintFormatSniff.php @@ -75,6 +75,10 @@ public function process(File $phpcsFile, $pointer): void return; } + if ($this->shortNullable !== self::YES && SniffSettingsHelper::isEnabledByPhpVersion(null, 80000) === false) { + $this->shortNullable = self::YES; + } + $tokens = $phpcsFile->getTokens(); if ($tokens[$pointer]['code'] === T_VARIABLE) { diff --git a/doc/type-hints.md b/doc/type-hints.md index 5b482015c..e16a56b97 100644 --- a/doc/type-hints.md +++ b/doc/type-hints.md @@ -42,7 +42,7 @@ Sniff provides the following settings: * `enable`: either to enable or not this sniff. By default, it is enabled for PHP versions 8.0 or higher. * `withSpacesAroundOperators`: `yes` requires spaces around `|` and `&`, `no` requires no space around `|`and `&`. None is set by default so both are enabled. * `withSpacesInsideParentheses`: `yes` requires spaces inside parentheses, `no` requires no spaces inside parentheses. None is set by default so both are enabled. -* `shortNullable`: `yes` requires usage of `?` for nullable type hint, `no` disallows it. None is set by default so both are enabled. +* `shortNullable`: `yes` requires usage of `?` for nullable type hint, `no` disallows it. None is set by default so both are enabled. For PHP versions below 8.0 it is set to `yes` by default. * `nullPosition`: `first` requires `null` on first position in the type hint, `last` requires last position. None is set by default so `null` can be everywhere. #### SlevomatCodingStandard.TypeHints.LongTypeHints 🔧 @@ -138,6 +138,8 @@ Sniff provides the following settings: #### SlevomatCodingStandard.TypeHints.UnionTypeHintFormat 🔧 +Deprecated: Use `SlevomatCodingStandard.TypeHints.DNFTypeHintFormat` instead + Checks format of union type hints. Sniff provides the following settings: