Skip to content

Commit

Permalink
#40 - forcing nullable type declaration for default null values (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofrewak authored Nov 29, 2021
1 parent 4d581e0 commit 0b24f70
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Configuration/Defaults/CommonAdditionalRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\UseArrowFunctionsFixer;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer;
Expand Down Expand Up @@ -60,5 +61,6 @@ class CommonAdditionalRules extends Rules implements AdditionalRules
"arguments",
],
],
NullableTypeDeclarationForDefaultNullValueFixer::class => null,
];
}
14 changes: 14 additions & 0 deletions tests/codestyle/fixtures/nullableTypeForDefaultNull/actual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class NullableTypeForDefaultNull
{
public function getNameLabel(string $name, string $title = null): string
{
$label = $name;
if ($title !== null) {
$label .= " " . $title;
}

return $label;
}
}
16 changes: 16 additions & 0 deletions tests/codestyle/fixtures/nullableTypeForDefaultNull/expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

class NullableTypeForDefaultNull
{
public function getNameLabel(string $name, ?string $title = null): string
{
$label = $name;
if ($title !== null) {
$label .= " " . $title;
}

return $label;
}
}
5 changes: 5 additions & 0 deletions tests/unit/AdditionalRulesConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer;
use PhpCsFixer\Fixer\FunctionNotation\UseArrowFunctionsFixer;
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer;
Expand Down Expand Up @@ -69,6 +70,7 @@ public function testAdditionalRulesConfiguration(): void
"arguments",
],
],
NullableTypeDeclarationForDefaultNullValueFixer::class => null,
],
$config->options()["rules"],
);
Expand Down Expand Up @@ -123,6 +125,7 @@ public function testFilteringAdditionalRulesConfiguration(): void
"arguments",
],
],
NullableTypeDeclarationForDefaultNullValueFixer::class => null,
],
$config->options()["rules"],
);
Expand Down Expand Up @@ -174,6 +177,7 @@ public function testExtendingAdditionalRulesConfiguration(): void
"arguments",
],
],
NullableTypeDeclarationForDefaultNullValueFixer::class => null,
HeredocToNowdocFixer::class => null,
],
$config->options()["rules"],
Expand Down Expand Up @@ -233,6 +237,7 @@ public function testExtendingWithOptionsAdditionalRulesConfiguration(): void
"arguments",
],
],
NullableTypeDeclarationForDefaultNullValueFixer::class => null,
NoMixedEchoPrintFixer::class => [
"use" => "echo",
],
Expand Down

0 comments on commit 0b24f70

Please sign in to comment.