Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 11c9862

Browse files
committed
Feat: Re-add fixers for property/parameter/return types and constructor property promotion
1 parent 53433cf commit 11c9862

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

‎ecs.php‎

Lines changed: 31 additions & 0 deletions
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
@@ -519,6 +538,18 @@
519538
// Allow single line closures
520539
ScopeClosingBraceSniff::class . '.ContentBefore' => null,
521540

541+
// Skip unwanted rules from PropertyTypeHintSniff
542+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
543+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
544+
545+
// Skip unwanted rules from ParameterTypeHintSniff
546+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
547+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
548+
549+
// Skip unwanted rules from ReturnTypeHintSniff
550+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
551+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
552+
522553
// We use declare(strict_types=1); after opening tag
523554
BlankLineAfterOpeningTagFixer::class => null,
524555
]);

‎tests/Integration/Fixtures/NewPhpFeatures.correct.php.inc‎

Lines changed: 1 addition & 4 deletions
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(

‎tests/Integration/Fixtures/NewPhpFeatures.wrong.php.inc‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /