From b92ea4c6440297c954f75bc46d02699de60b1ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Thu, 9 May 2024 18:00:37 +0200 Subject: [PATCH] Feat: Add NullableTypeDeclarationFixer to standardize nullable declaration using `?` (part of #94) --- ecs.php | 3 +++ tests/Integration/Fixtures/Basic.correct.php.inc | 3 +++ tests/Integration/Fixtures/Basic.wrong.php.inc | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/ecs.php b/ecs.php index be2de95..5cd61c7 100644 --- a/ecs.php +++ b/ecs.php @@ -89,6 +89,7 @@ use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer; use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer; +use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer; use PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAroundConstructFixer; use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer; use PhpCsFixer\Fixer\NamespaceNotation\BlankLinesBeforeNamespaceFixer; @@ -311,6 +312,8 @@ DeclareEqualNormalizeFixer::class, // Replaces `is_null($var)` expression with `null === $var` IsNullFixer::class, + // Nullable single type declaration should be standardised using question mark syntax. + NullableTypeDeclarationFixer::class, // Ensures a single space around language constructs. SingleSpaceAroundConstructFixer::class, // Namespace must not contain spacing, comments or PHPDoc. diff --git a/tests/Integration/Fixtures/Basic.correct.php.inc b/tests/Integration/Fixtures/Basic.correct.php.inc index 9f2d726..4ff5c04 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -170,4 +170,7 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully 2, ); } + + // NullableTypeDeclarationFixer + public function withParameters(?string $nullableValue): void {} } diff --git a/tests/Integration/Fixtures/Basic.wrong.php.inc b/tests/Integration/Fixtures/Basic.wrong.php.inc index e54f569..39f1a87 100644 --- a/tests/Integration/Fixtures/Basic.wrong.php.inc +++ b/tests/Integration/Fixtures/Basic.wrong.php.inc @@ -167,4 +167,8 @@ but should be heredoc instead'; 2 ); } + + // NullableTypeDeclarationFixer + public function withParameters(null|string $nullableValue): void + {} }