Skip to content

Commit ad7f959

Browse files
committed
Feat: Add NullableTypeDeclarationFixer to standardize nullable declaration using ? (part of #94)
1 parent eb1479e commit ad7f959

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
9090
use PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer;
9191
use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer;
92+
use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer;
9293
use PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAroundConstructFixer;
9394
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
9495
use PhpCsFixer\Fixer\NamespaceNotation\BlankLinesBeforeNamespaceFixer;
@@ -311,6 +312,8 @@
311312
DeclareEqualNormalizeFixer::class,
312313
// Replaces `is_null($var)` expression with `null === $var`
313314
IsNullFixer::class,
315+
// Nullable single type declaration should be standardised using question mark syntax.
316+
NullableTypeDeclarationFixer::class,
314317
// Ensures a single space around language constructs.
315318
SingleSpaceAroundConstructFixer::class,
316319
// Namespace must not contain spacing, comments or PHPDoc.

tests/Integration/Fixtures/Basic.correct.php.inc

+3
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,7 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
170170
2,
171171
);
172172
}
173+
174+
// NullableTypeDeclarationFixer
175+
public function withParameters(?string $nullableValue): void {}
173176
}

tests/Integration/Fixtures/Basic.wrong.php.inc

+4
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,8 @@ but should be heredoc instead';
167167
2
168168
);
169169
}
170+
171+
// NullableTypeDeclarationFixer
172+
public function withParameters(null|string $nullableValue): void
173+
{}
170174
}

0 commit comments

Comments
 (0)