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 4395da4

Browse files
committed
Feat: Re-add fixers for property/parameter/return types and constructor property promotion
1 parent 26ec573 commit 4395da4

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;
@@ -130,10 +133,14 @@
130133
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
131134
use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer;
132135
use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer;
136+
use SlevomatCodingStandard\Sniffs\Classes\RequireConstructorPropertyPromotionSniff;
133137
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff;
134138
use SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff;
135139
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInCallSniff;
136140
use SlevomatCodingStandard\Sniffs\Functions\RequireTrailingCommaInDeclarationSniff;
141+
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
142+
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff;
143+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
137144
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
138145
use Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer;
139146
use Symplify\EasyCodingStandard\Config\ECSConfig;
@@ -370,6 +377,18 @@
370377
ReferenceThrowableOnlySniff::class,
371378
// The @param, @return, @var and inline @var annotations should keep standard format
372379
ParamReturnAndVarTagMalformsFixer::class,
380+
// Takes `@var` annotation of non-mixed types and adjusts accordingly the property signature to a native PHP 7.4+ type-hint.
381+
PhpdocToPropertyTypeFixer::class,
382+
PropertyTypeHintSniff::class,
383+
// Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature to a native type-hints.
384+
PhpdocToParamTypeFixer::class,
385+
ParameterTypeHintSniff::class,
386+
// Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature.
387+
PhpdocToReturnTypeFixer::class,
388+
ReturnTypeHintSniff::class,
389+
// Promote constructor properties
390+
// For php-cs-fixer implementation @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5956
391+
RequireConstructorPropertyPromotionSniff::class,
373392

374393
// switch -> match
375394
// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5894
@@ -511,6 +530,18 @@
511530
// Allow single line closures
512531
ScopeClosingBraceSniff::class . '.ContentBefore' => null,
513532

533+
// Skip unwanted rules from PropertyTypeHintSniff
534+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
535+
PropertyTypeHintSniff::class . '.' . PropertyTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
536+
537+
// Skip unwanted rules from ParameterTypeHintSniff
538+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
539+
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
540+
541+
// Skip unwanted rules from ReturnTypeHintSniff
542+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION => null,
543+
ReturnTypeHintSniff::class . '.' . ReturnTypeHintSniff::CODE_MISSING_ANY_TYPE_HINT => null,
544+
514545
// We use declare(strict_types=1); after opening tag
515546
BlankLineAfterOpeningTagFixer::class => null,
516547
]);

‎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 によって変換されたページ (->オリジナル) /