Skip to content

Commit

Permalink
Merge 6b07446 into cde08b1
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM authored Apr 28, 2024
2 parents cde08b1 + 6b07446 commit 40ac428
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ecs-internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

/**
/*
* Internal rules configuration for the lmc/coding-standard project itself
*/
return ECSConfig::configure()
Expand Down
13 changes: 8 additions & 5 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
use PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer;
Expand Down Expand Up @@ -133,6 +134,7 @@
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer;
use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer;
use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer;
use SlevomatCodingStandard\Sniffs\Classes\RequireConstructorPropertyPromotionSniff;
use SlevomatCodingStandard\Sniffs\ControlStructures\RequireNullSafeObjectOperatorSniff;
use SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff;
Expand All @@ -141,7 +143,6 @@
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
use Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

Expand Down Expand Up @@ -213,8 +214,6 @@
ArrayPushFixer::class,
// Replace non multibyte-safe functions with corresponding mb function
MbStrFunctionsFixer::class,
// Master functions shall be used instead of aliases
NoAliasFunctionsFixer::class,
// Replaces `rand`, `srand`, `getrandmax` functions calls with their `mt_*` analogs
RandomApiMigrationFixer::class,
// Cast shall be used, not `settype()`
Expand Down Expand Up @@ -263,6 +262,8 @@
FopenFlagsFixer::class,
// Add missing space between function's argument and its typehint.
TypeDeclarationSpacesFixer::class,
// None space should be around union type and intersection type operators.
TypesSpacesFixer::class,
// Function `implode` must be called with 2 arguments in the documented order.
ImplodeCallFixer::class,
// Lambda must not import variables it doesn't use.
Expand Down Expand Up @@ -331,6 +332,8 @@
PhpdocSingleLineVarSpacingFixer::class,
// PHPDoc should start and end with content
PhpdocTrimFixer::class,
// Docblocks should only be used on structural elements.
PhpdocToCommentFixer::class,
// The correct case must be used for standard PHP types in PHPDoc.
PhpdocTypesFixer::class,
// `@var` and `@type` annotations must have type and name in the correct order
Expand Down Expand Up @@ -453,6 +456,8 @@
'var_dump' => null,
],
])
// Master functions shall be used instead of aliases
->withConfiguredRule(NoAliasFunctionsFixer::class, ['sets' => ['@all']])
// There should be exactly one blank line before a namespace declaration.
->withConfiguredRule(BlankLinesBeforeNamespaceFixer::class, ['min_line_breaks' => 2, 'max_line_breaks' => 2])
// Proper operator spacing
Expand Down Expand Up @@ -500,8 +505,6 @@
'use_trait',
],
])
// Format union types
->withConfiguredRule(UnionTypeHintFormatSniff::class, ['withSpaces' => 'no'])
->withSkip([
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
EmptyStatementSniff::class . '.DetectedCatch' => null,
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class Basic

public function fooBar(mixed $foo): mixed
{
// PhpdocToCommentFixer
/*
* Phpdoc used instead of plain comment
*/
if ($foo === 'bar') {
// NoAliasFunctionsFixer
$baz = implode(',', ['foo', 'bar']);
}

// TernaryToElvisOperatorFixer
return ($foo ?: 'not true');
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class Basic

public function fooBar(mixed $foo): mixed
{
// PhpdocToCommentFixer
/**
* Phpdoc used instead of plain comment
*/
if ($foo === 'bar') {
// NoAliasFunctionsFixer
$baz = join(',', ['foo', 'bar']);
}

// TernaryToElvisOperatorFixer
return ($foo ? $foo : 'not true');
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Integration/Fixtures/NewPhpFeatures.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NewPhpFeatures
}

public function php80features(
string|bool $foo, // UnionTypeHintFormatSniff
string|bool $foo, // TypesSpacesFixer
int $bar, // RequireTrailingCommaInDeclarationSniff
): string|bool {
$value = mt_rand(
Expand All @@ -20,6 +20,9 @@ class NewPhpFeatures
$dateOrNull = $this->mayReturnDateTimeOrNull();
$timestamp = $dateOrNull?->getTimestamp(); // RequireNullSafeObjectOperatorSniff

// AssignNullCoalescingToCoalesceEqualFixer
$name = $_GET['name'] ?? 'default';

return $foo;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Integration/Fixtures/NewPhpFeatures.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NewPhpFeatures
}

public function php80features(
string | bool $foo, // UnionTypeHintFormatSniff
string | bool $foo, // TypesSpacesFixer
int $bar // RequireTrailingCommaInDeclarationSniff
): string | bool {
$value = mt_rand(
Expand All @@ -23,6 +23,9 @@ class NewPhpFeatures
$dateOrNull = $this->mayReturnDateTimeOrNull();
$timestamp = $dateOrNull !== null ? $dateOrNull->getTimestamp() : null; // RequireNullSafeObjectOperatorSniff

// AssignNullCoalescingToCoalesceEqualFixer
$name = isset($_GET['name']) ? $_GET['name'] : 'default';

return $foo;
}

Expand Down

0 comments on commit 40ac428

Please sign in to comment.