Skip to content

Commit

Permalink
Feat: Add NullableTypeDeclarationForDefaultNullValueFixer (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 9, 2024
1 parent 6a20107 commit f77ef49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer;
use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer;
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
Expand Down Expand Up @@ -295,6 +296,8 @@
NoUnreachableDefaultArgumentValueFixer::class,
// There must be no `sprintf` calls with only the first argument.
NoUselessSprintfFixer::class,
// Add `?` before single type declarations when parameters have a default null value.
NullableTypeDeclarationForDefaultNullValueFixer::class,
// There must not be a space before colon in return type declarations.
ReturnTypeDeclarationFixer::class,
// Add `void` return type to functions with missing or empty return statements.
Expand Down
8 changes: 6 additions & 2 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
);
}

// NullableTypeDeclarationFixer
public function withParameters(?string $nullableValue): void {}
public function withParameters(
// NullableTypeDeclarationFixer
?string $nullableValue,
// NullableTypeDeclarationForDefaultNullValueFixer
?string $anotherNullableValue = null,
): void {}
}
9 changes: 6 additions & 3 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ but should be heredoc instead';
);
}

// NullableTypeDeclarationFixer
public function withParameters(null|string $nullableValue): void
{}
public function withParameters(
// NullableTypeDeclarationFixer
null|string $nullableValue,
// NullableTypeDeclarationForDefaultNullValueFixer
string $anotherNullableValue = null,
): void {}
}

0 comments on commit f77ef49

Please sign in to comment.