Skip to content

Commit 15f1ab3

Browse files
committed
Feat: Re-add fixers for property/parameter/return types and constructor property promotion
1 parent a003e9a commit 15f1ab3

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

Diff for: ecs.php

+31
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
use PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer;
7070
use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer;
7171
use PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer;
72+
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
73+
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer;
74+
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer;
7275
use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer;
7376
use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer;
7477
use PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer;
@@ -131,10 +134,14 @@
131134
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
132135
use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer;
133136
use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer;
137+
use SlevomatCodingStandard\Sniffs\Classes\RequireConstructorPropertyPromotionSniff;
134138
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff;
135139
use SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff;
136140
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInCallSniff;
137141
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInDeclarationSniff;
142+
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
143+
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff;
144+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
138145
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
139146
use Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer;
140147
use Symplify\EasyCodingStandard\Config\ECSConfig;
@@ -373,6 +380,18 @@
373380
ReferenceThrowableOnlySniff::class,
374381
// The @param, @return, @var and inline @var annotations should keep standard format
375382
ParamReturnAndVarTagMalformsFixer::class,
383+
// Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature to a native PHP 7.4+ type-hint.
384+
PhpdocToPropertyTypeFixer::class,
385+
PropertyTypeHintSniff::class,
386+
// Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature to a native type-hints.
387+
PhpdocToParamTypeFixer::class,
388+
ParameterTypeHintSniff::class,
389+
// Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature.
390+
PhpdocToReturnTypeFixer::class,
391+
ReturnTypeHintSniff::class,
392+
// Promote constructor properties
393+
// For php-cs-fixer implementation @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5956
394+
RequireConstructorPropertyPromotionSniff::class,
376395

377396
// switch -> match
378397
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5894
@@ -514,6 +533,18 @@
514533
// Allow single line closures
515534
ScopeClosingBraceSniff::class . '.ContentBefore' => null,
516535

536+
// Skip unwanted rules from PropertyTypeHintSniff
537+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
538+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
539+
540+
// Skip unwanted rules from ParameterTypeHintSniff
541+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
542+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
543+
544+
// Skip unwanted rules from ReturnTypeHintSniff
545+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
546+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
547+
517548
// We use declare(strict_types=1); after opening tag
518549
BlankLineAfterOpeningTagFixer::class => null,
519550
]);

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ namespace Lmc\CodingStandard\Integration\Fixtures;
44

55
class NewPhpFeatures
66
{
7-
private string $someString;
8-
9-
public function __construct(string $someString)
7+
public function __construct(private string $someString) // RequireConstructorPropertyPromotionSniff
108
{
11-
$this->someString = $someString;
129
}
1310

1411
public function php80features(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class NewPhpFeatures
66
{
77
private string $someString;
88

9-
public function __construct(string $someString)
9+
public function __construct(string $someString) // RequireConstructorPropertyPromotionSniff
1010
{
1111
$this->someString = $someString;
1212
}

0 commit comments

Comments
 (0)