Skip to content

Commit d1e6550

Browse files
committed
Feat: Add NullableTypeDeclarationForDefaultNullValueFixer (part of #94)
1 parent b92ea4c commit d1e6550

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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;
@@ -296,6 +297,8 @@
296297
NoUnreachableDefaultArgumentValueFixer::class,
297298
// There must be no `sprintf` calls with only the first argument.
298299
NoUselessSprintfFixer::class,
300+
// Add `?` before single type declarations when parameters have a default null value.
301+
NullableTypeDeclarationForDefaultNullValueFixer::class,
299302
// There must not be a space before colon in return type declarations.
300303
ReturnTypeDeclarationFixer::class,
301304
// Add `void` return type to functions with missing or empty return statements.

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

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

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ but should be heredoc instead';
168168
);
169169
}
170170

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

0 commit comments

Comments
 (0)