From 6a20107a345414cc96716b17ecd7715e72b1fe46 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 50235de..dea4872 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; @@ -310,6 +311,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 f94ea3d..e714ccc 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -168,4 +168,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 a140cf5..8cd6609 100644 --- a/tests/Integration/Fixtures/Basic.wrong.php.inc +++ b/tests/Integration/Fixtures/Basic.wrong.php.inc @@ -165,4 +165,8 @@ but should be heredoc instead'; 2 ); } + + // NullableTypeDeclarationFixer + public function withParameters(null|string $nullableValue): void + {} }