code-quality/config/ecs.php

116 lines
4.2 KiB
PHP
Raw Normal View History

2022-10-12 17:46:05 +00:00
<?php declare(strict_types=1);
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
2023-11-29 17:27:33 +00:00
use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer;
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
use PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer;
2023-11-29 17:27:33 +00:00
use PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer;
2022-10-12 17:46:05 +00:00
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;
use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer;
2023-01-25 21:33:15 +00:00
use SlevomatCodingStandard\Sniffs\Attributes\AttributeAndTargetSpacingSniff;
2022-10-12 17:46:05 +00:00
use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff;
use SlevomatCodingStandard\Sniffs\ControlStructures\NewWithoutParenthesesSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\MultipleUsesPerLineSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
2024-01-25 17:31:04 +00:00
return ECSConfig::configure()
->withPreparedSets(
symplify: true,
2024-01-25 17:31:04 +00:00
arrays: true,
comments: true,
docblocks: true,
spaces: true,
namespaces: true,
controlStructures: true,
2024-01-25 17:31:04 +00:00
strict: true,
cleanCode: true
2024-01-25 17:31:04 +00:00
)
->withPhpCsFixerSets(
perCS: true,
perCSRisky: true,
php80MigrationRisky: true,
php83Migration: true,
2024-01-25 17:31:04 +00:00
)
->withRules([
2022-10-12 17:46:05 +00:00
AlphabeticallySortedUsesSniff::class,
DisallowGroupUseSniff::class,
MultipleUsesPerLineSniff::class,
NamespaceSpacingSniff::class,
2023-11-29 17:27:33 +00:00
OperatorLinebreakFixer::class,
2024-01-25 17:31:04 +00:00
NoWhitespaceInBlankLineFixer::class,
NewWithoutParenthesesSniff::class,
])
->withConfiguredRule(ClassConstantVisibilitySniff::class, [
'fixable' => true,
])
->withConfiguredRule(
2022-10-12 17:46:05 +00:00
ReferenceUsedNamesOnlySniff::class,
[
'allowFallbackGlobalConstants' => false,
'allowFallbackGlobalFunctions' => false,
'allowFullyQualifiedGlobalClasses' => false,
'allowFullyQualifiedGlobalConstants' => false,
'allowFullyQualifiedGlobalFunctions' => false,
'allowFullyQualifiedNameForCollidingClasses' => true,
'allowFullyQualifiedNameForCollidingConstants' => true,
'allowFullyQualifiedNameForCollidingFunctions' => true,
'searchAnnotations' => true,
]
2024-01-25 17:31:04 +00:00
)
2022-10-12 17:46:05 +00:00
// define newlines between use statements
2024-01-25 17:31:04 +00:00
->withConfiguredRule(
UseSpacingSniff::class,
[
'linesCountAfterLastUse' => 1,
'linesCountBeforeFirstUse' => 1,
'linesCountBetweenUseTypes' => 1,
]
)
->withConfiguredRule(
2024-05-04 17:41:48 +00:00
\PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer::class,
[
'elements' => ['const' => 'none', 'method' => 'one', 'property' => 'none', 'trait_import' => 'none', 'case' => 'none'],
],
)->withConfiguredRule(
2022-10-12 17:46:05 +00:00
DeclareStrictTypesSniff::class,
[
'declareOnFirstLine' => true,
'spacesCountAroundEqualsSign' => 0,
]
2024-01-25 17:31:04 +00:00
)
->withConfiguredRule(
UnionTypeHintFormatSniff::class,
[
'nullPosition' => 'last',
'shortNullable' => 'no',
'withSpaces' => 'no',
]
)
->withConfiguredRule(
2022-10-12 17:46:05 +00:00
NoExtraBlankLinesFixer::class,
[
'tokens' => ['square_brace_block', 'return', 'extra'],
]
2024-01-25 17:31:04 +00:00
)
->withConfiguredRule(AttributeAndTargetSpacingSniff::class, [
2023-01-25 21:33:15 +00:00
'linesCount' => 0,
2024-01-25 17:31:04 +00:00
])
->withSkip([
BlankLineAfterOpeningTagFixer::class,
OrderedImportsFixer::class,
FunctionToConstantFixer::class,
NewWithParenthesesFixer::class,
NewWithBracesFixer::class,
2024-04-25 19:01:06 +00:00
LineLengthFixer::class,
2023-01-25 21:33:15 +00:00
]);