Skip to content

Commit

Permalink
minor #6030 SingleSpaceAfterConstructFixer - Add switch support (Sp…
Browse files Browse the repository at this point in the history
…acePossum)

This PR was merged into the master branch.

Discussion
----------

SingleSpaceAfterConstructFixer - Add `switch` support

Commits
-------

a84ab76 SingleSpaceAfterConstructFixer - Add `switch` support
  • Loading branch information
SpacePossum committed Sep 25, 2021
2 parents 5b298e5 + a84ab76 commit 80e0efd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/rules/language_construct/single_space_after_construct.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Configuration

List of constructs which must be followed by a single space.

Allowed values: a subset of ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``
Allowed values: a subset of ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``

Default value: ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``
Default value: ``['abstract', 'as', 'attribute', 'break', 'case', 'catch', 'class', 'clone', 'comment', 'const', 'const_import', 'continue', 'do', 'echo', 'else', 'elseif', 'extends', 'final', 'finally', 'for', 'foreach', 'function', 'function_import', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'match', 'named_argument', 'namespace', 'new', 'open_tag_with_echo', 'php_doc', 'php_open', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'use', 'use_lambda', 'use_trait', 'var', 'while', 'yield', 'yield_from']``

Examples
--------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ final class SingleSpaceAfterConstructFixer extends AbstractFixer implements Conf
'require_once' => T_REQUIRE_ONCE,
'return' => T_RETURN,
'static' => T_STATIC,
'switch' => T_SWITCH,
'throw' => T_THROW,
'trait' => T_TRAIT,
'try' => T_TRY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3180,4 +3180,32 @@ public function __construct(
',
];
}

/**
* @dataProvider provideFixWithSwitchCases
*/
public function testFixWithSwitch(string $expected, string $input): void
{
$this->fixer->configure([
'constructs' => [
'switch',
],
]);

$this->doTest($expected, $input);
}

public function provideFixWithSwitchCases(): \Generator
{
yield [
'<?php
switch ($a){ case 1: echo 123; }
switch ($b){ case 1: echo 123; }
',
'<?php
switch($a){ case 1: echo 123; }
switch ($b){ case 1: echo 123; }
',
];
}
}

0 comments on commit 80e0efd

Please sign in to comment.