Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: @Symfony - reconfigure trailing commas #7671

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/ruleSets/Symfony.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ Rules
``['stick_comment_to_next_continuous_control_statement' => true]``

- `switch_continue_to_break <./../rules/control_structure/switch_continue_to_break.rst>`_
- `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_
- `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_ with config:

``['elements' => ['arrays', 'match', 'parameters']]``

- `trim_array_spaces <./../rules/array_notation/trim_array_spaces.rst>`_
- `type_declaration_spaces <./../rules/whitespace/type_declaration_spaces.rst>`_
- `types_spaces <./../rules/whitespace/types_spaces.rst>`_
Expand Down
10 changes: 8 additions & 2 deletions doc/rules/control_structure/trailing_comma_in_multiline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ The rule is part of the following rule sets:

``['after_heredoc' => true]``

- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
- `@Symfony <./../../ruleSets/Symfony.rst>`_
- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:

``['elements' => ['arrays', 'match', 'parameters']]``

- `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:

``['elements' => ['arrays', 'match', 'parameters']]``


References
----------
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/FileCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
FileHandlerInterface $handler,
SignatureInterface $signature,
bool $isDryRun = false,
?DirectoryInterface $cacheDirectory = null
?DirectoryInterface $cacheDirectory = null,
) {
$this->handler = $handler;
$this->signature = $signature;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class SelfUpdateCommand extends Command
public function __construct(
NewVersionCheckerInterface $versionChecker,
ToolInfoInterface $toolInfo,
PharCheckerInterface $pharChecker
PharCheckerInterface $pharChecker,
) {
parent::__construct();

Expand Down
2 changes: 1 addition & 1 deletion src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function __construct(
ConfigInterface $config,
array $options,
string $cwd,
ToolInfoInterface $toolInfo
ToolInfoInterface $toolInfo,
) {
$this->defaultConfig = $config;
$this->cwd = $cwd;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Output/OutputContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class OutputContext
public function __construct(
?OutputInterface $output,
int $terminalWidth,
int $filesCount
int $filesCount,
) {
$this->output = $output;
$this->terminalWidth = $terminalWidth;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Report/FixReport/ReportSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
int $memory,
bool $addAppliedFixers,
bool $isDryRun,
bool $isDecoratedOutput
bool $isDecoratedOutput,
) {
$this->changed = $changed;
$this->filesCount = $filesCount;
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/AbstractPhpUnitFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final protected function ensureIsDockBlockWithAnnotation(
Tokens $tokens,
int $index,
string $annotation,
array $preventingAnnotations
array $preventingAnnotations,
): void {
$docBlockIndex = $this->getDocBlockIndex($tokens, $index);

Expand Down Expand Up @@ -121,7 +121,7 @@ private function updateDocBlockIfNeeded(
Tokens $tokens,
int $docBlockIndex,
string $annotation,
array $preventingAnnotations
array $preventingAnnotations,
): void {
$doc = new DocBlock($tokens[$docBlockIndex]->getContent());
foreach ($preventingAnnotations as $preventingAnnotation) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/AbstractShortOperatorFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function shortenOperation(
int $equalsIndex,
int $operatorIndex,
array $assignRange,
array $operatorRange
array $operatorRange,
): void {
$tokens[$equalsIndex] = $this->getReplacementToken($tokens[$operatorIndex]);
$tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndex);
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Alias/SetTypeToCastFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function removeSettypeCall(
int $firstArgumentStart,
int $commaIndex,
int $secondArgumentStart,
int $closeParenthesisIndex
int $closeParenthesisIndex,
): void {
$tokens->clearTokenAndMergeSurroundingWhitespace($closeParenthesisIndex);
$prevIndex = $tokens->getPrevMeaningfulToken($closeParenthesisIndex);
Expand All @@ -201,7 +201,7 @@ private function fixSettypeCall(
Tokens $tokens,
int $functionNameIndex,
Token $argumentToken,
Token $castToken
Token $castToken,
): void {
$tokens->insertAt(
$functionNameIndex,
Expand All @@ -222,7 +222,7 @@ private function fixSettypeCall(
private function fixSettypeNullCall(
Tokens $tokens,
int $functionNameIndex,
Token $argumentToken
Token $argumentToken,
): void {
$tokens->insertAt(
$functionNameIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ private function removeUselessParenthesisPair(
int $afterCloseIndex,
int $openIndex,
int $closeIndex,
?string $configType
?string $configType,
): void {
$statements = $this->configuration['statements'];

Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ControlStructure/YodaStyleFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private function fixTokensCompare(
int $endLeft,
int $compareOperatorIndex,
int $startRight,
int $endRight
int $endRight,
): int {
$type = $tokens[$compareOperatorIndex]->getId();
$content = $tokens[$compareOperatorIndex]->getContent();
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/LanguageConstruct/FunctionToConstantFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function fixFunctionCallToConstant(Tokens $tokens, int $index, int $brac
private function getReplaceCandidate(
Tokens $tokens,
FunctionsAnalyzer $functionAnalyzer,
int $index
int $index,
): ?array {
if (!$tokens[$index]->isGivenKind(T_STRING)) {
return null;
Expand Down Expand Up @@ -219,7 +219,7 @@ private function getReplaceCandidate(
private function fixGetClassCall(
Tokens $tokens,
FunctionsAnalyzer $functionAnalyzer,
int $index
int $index,
): ?array {
if (!isset($this->functionsFixMap['get_class']) && !isset($this->functionsFixMap['get_class_this'])) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Operator/NoUselessConcatOperatorFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function mergeConstantEscapedStringOperands(
Tokens $tokens,
array $firstOperand,
int $concatOperatorIndex,
array $secondOperand
array $secondOperand,
): void {
$quote = self::STR_DOUBLE_QUOTE === $firstOperand['type'] || self::STR_DOUBLE_QUOTE === $secondOperand['type'] ? '"' : "'";
$firstOperandTokenContent = $tokens[$firstOperand['start']]->getContent();
Expand Down Expand Up @@ -264,7 +264,7 @@ private function mergeConstantEscapedStringVarOperands(
Tokens $tokens,
array $firstOperand,
int $concatOperatorIndex,
array $secondOperand
array $secondOperand,
): void {
// build uo the new content
$newContent = '';
Expand Down
6 changes: 3 additions & 3 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private function fixFunctionDocComment(
array $element,
?string $namespace,
?string $currentSymbol,
array $shortNames
array $shortNames,
): string {
$docBlock = new DocBlock($content);

Expand Down Expand Up @@ -368,7 +368,7 @@ private function fixPropertyDocComment(
array $element,
?string $namespace,
?string $currentSymbol,
array $shortNames
array $shortNames,
): string {
if (\count($element['types']) > 0) {
$propertyTypeInfo = $this->parseTypeHint($tokens, array_key_first($element['types']));
Expand Down Expand Up @@ -517,7 +517,7 @@ private function annotationIsSuperfluous(
array $info,
?string $namespace,
?string $currentSymbol,
array $symbolShortNames
array $symbolShortNames,
): bool {
if ('param' === $annotation->getTag()->getName()) {
$regex = '{\*\h*@param(?:\h+'.TypeExpression::REGEX_TYPES.')?(?!\S)(?:\h+(?:\&\h*)?(?:\.{3}\h*)?\$\S+)?(?:\h+(?<description>(?!\*+\/)\S+))?}s';
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/ReturnNotation/ReturnAssignmentFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private function simplifyReturnStatement(
int $assignVarIndex,
int $assignVarOperatorIndex,
int $returnIndex,
int $returnVarEndIndex
int $returnVarEndIndex,
): int {
$inserted = 0;
$originalIndent = $tokens[$assignVarIndex - 1]->isWhitespace()
Expand Down
2 changes: 1 addition & 1 deletion src/FixerConfiguration/FixerOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(
$default = null,
?array $allowedTypes = null,
?array $allowedValues = null,
?\Closure $normalizer = null
?\Closure $normalizer = null,
) {
if ($isRequired && null !== $default) {
throw new \LogicException('Required options cannot have a default value.');
Expand Down
2 changes: 1 addition & 1 deletion src/FixerDefinition/FileSpecificCodeSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class FileSpecificCodeSample implements FileSpecificCodeSampleInterface
public function __construct(
string $code,
\SplFileInfo $splFileInfo,
?array $configuration = null
?array $configuration = null,
) {
$this->codeSample = new CodeSample($code, $configuration);
$this->splFileInfo = $splFileInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/FixerDefinition/FixerDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
string $summary,
array $codeSamples,
?string $description = null,
?string $riskyDescription = null
?string $riskyDescription = null,
) {
$this->summary = $summary;
$this->codeSamples = $codeSamples;
Expand Down
2 changes: 1 addition & 1 deletion src/FixerDefinition/VersionSpecificCodeSample.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class VersionSpecificCodeSample implements VersionSpecificCodeSampleInterf
public function __construct(
string $code,
VersionSpecificationInterface $versionSpecification,
?array $configuration = null
?array $configuration = null,
) {
$this->codeSample = new CodeSample($code, $configuration);
$this->versionSpecification = $versionSpecification;
Expand Down
8 changes: 6 additions & 2 deletions src/RuleSet/Sets/SymfonySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public function getRules(): array
'no_useless_nullsafe_operator' => true,
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false],
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => false,
],
'object_operator_without_whitespace' => true,
'operator_linebreak' => [
'only_booleans' => true,
Expand Down Expand Up @@ -211,7 +213,9 @@ public function getRules(): array
'stick_comment_to_next_continuous_control_statement' => true,
],
'switch_continue_to_break' => true,
'trailing_comma_in_multiline' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arrays', 'match', 'parameters'],
],
'trim_array_spaces' => true,
'type_declaration_spaces' => true,
'types_spaces' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/FileFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class FileFilterIterator extends \FilterIterator
public function __construct(
\Traversable $iterator,
?EventDispatcherInterface $eventDispatcher,
CacheManagerInterface $cacheManager
CacheManagerInterface $cacheManager,
) {
if (!$iterator instanceof \Iterator) {
$iterator = new \IteratorIterator($iterator);
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(
bool $isDryRun,
CacheManagerInterface $cacheManager,
?DirectoryInterface $directory = null,
bool $stopOnViolation = false
bool $stopOnViolation = false,
) {
$this->finder = $finder;
$this->fixers = $fixers;
Expand Down
2 changes: 1 addition & 1 deletion tests/AbstractFunctionReferenceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testAbstractFunctionReferenceFixer(
string $source,
string $functionNameToSearch,
int $start = 0,
?int $end = null
?int $end = null,
): void {
$fixer = $this->createAbstractFunctionReferenceFixerDouble();

Expand Down
2 changes: 1 addition & 1 deletion tests/AbstractProxyFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function createFixerDouble(
bool $isCandidate,
bool $isRisky = false,
bool $supports = false,
int $priority = 999
int $priority = 999,
): FixerInterface {
return new class($isCandidate, $isRisky, $supports, $priority) implements FixerInterface {
private bool $isCandidate;
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/Command/DescribeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private static function createFixerWithSamplesDouble(array $samples): FixerInter
* @param list<CodeSampleInterface> $samples
*/
public function __construct(
array $samples
array $samples,
) {
parent::__construct();
$this->samples = $samples;
Expand Down
8 changes: 4 additions & 4 deletions tests/Console/Command/SelfUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testExecute(
array $input,
bool $decorated,
string $expectedFileContents,
string $expectedDisplay
string $expectedDisplay,
): void {
$versionChecker = $this->createNewVersionCheckerDouble($latestVersion, $latestMinorVersion);

Expand Down Expand Up @@ -260,7 +260,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions(
bool $latestMajorVersionSuccess,
bool $latestMinorVersionSuccess,
array $input,
bool $decorated
bool $decorated,
): void {
$versionChecker = $this->createNewVersionCheckerDouble(
self::getNewMajorReleaseVersion(),
Expand Down Expand Up @@ -467,7 +467,7 @@ private function createNewVersionCheckerDouble(
string $latestVersion = Application::VERSION,
?string $latestMinorVersion = Application::VERSION,
bool $latestMajorVersionSuccess = true,
bool $latestMinorVersionSuccess = true
bool $latestMinorVersionSuccess = true,
): NewVersionCheckerInterface {
return new class($latestVersion, $latestMinorVersion, $latestMajorVersionSuccess, $latestMinorVersionSuccess) implements NewVersionCheckerInterface {
private string $latestVersion;
Expand All @@ -479,7 +479,7 @@ public function __construct(
string $latestVersion,
?string $latestMinorVersion,
bool $latestMajorVersionSuccess = true,
bool $latestMinorVersionSuccess = true
bool $latestMinorVersionSuccess = true,
) {
$this->latestVersion = $latestVersion;
$this->latestMinorVersion = $latestMinorVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ProgressOutputFactoryTest extends TestCase
public function testValidProcessOutputIsCreated(
string $outputType,
OutputContext $context,
string $expectedOutputClass
string $expectedOutputClass,
): void {
self::assertInstanceOf($expectedOutputClass, (new ProgressOutputFactory())->create($outputType, $context));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function provideConfigureRejectsInvalidConfigurationElementCases()
public function testConfigureIncludeSets(
array $include,
?string $expectedExceptionClass = null,
?string $expectedExceptionMessage = null
?string $expectedExceptionMessage = null,
): void {
if (null !== $expectedExceptionClass) {
$this->expectException($expectedExceptionClass);
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFix(
string $expected,
?string $input = null,
array $config = [],
?WhitespacesFixerConfig $whitespaceConfig = null
?WhitespacesFixerConfig $whitespaceConfig = null,
): void {
$this->fixer->configure($config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testFix(
string $expected,
?string $input = null,
?array $config = [],
?WhitespacesFixerConfig $whitespaces = null
?WhitespacesFixerConfig $whitespaces = null,
): void {
if (null !== $whitespaces) {
$this->fixer->setWhitespacesConfig($whitespaces);
Expand Down