Skip to content

Commit f77ef49

Browse files
committed
Feat: Add NullableTypeDeclarationForDefaultNullValueFixer (part of #94)
1 parent 6a20107 commit f77ef49

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Diff for: ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
7878
use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer;
7979
use PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer;
80+
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
8081
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
8182
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer;
8283
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
@@ -295,6 +296,8 @@
295296
NoUnreachableDefaultArgumentValueFixer::class,
296297
// There must be no `sprintf` calls with only the first argument.
297298
NoUselessSprintfFixer::class,
299+
// Add `?` before single type declarations when parameters have a default null value.
300+
NullableTypeDeclarationForDefaultNullValueFixer::class,
298301
// There must not be a space before colon in return type declarations.
299302
ReturnTypeDeclarationFixer::class,
300303
// Add `void` return type to functions with missing or empty return statements.

Diff for: tests/Integration/Fixtures/Basic.correct.php.inc

+6-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
169169
);
170170
}
171171

172-
// NullableTypeDeclarationFixer
173-
public function withParameters(?string $nullableValue): void {}
172+
public function withParameters(
173+
// NullableTypeDeclarationFixer
174+
?string $nullableValue,
175+
// NullableTypeDeclarationForDefaultNullValueFixer
176+
?string $anotherNullableValue = null,
177+
): void {}
174178
}

Diff for: tests/Integration/Fixtures/Basic.wrong.php.inc

+6-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ but should be heredoc instead';
166166
);
167167
}
168168

169-
// NullableTypeDeclarationFixer
170-
public function withParameters(null|string $nullableValue): void
171-
{}
169+
public function withParameters(
170+
// NullableTypeDeclarationFixer
171+
null|string $nullableValue,
172+
// NullableTypeDeclarationForDefaultNullValueFixer
173+
string $anotherNullableValue = null,
174+
): void {}
172175
}

0 commit comments

Comments
 (0)