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

switch should be followed by a space #7906

Open
hirasso opened this issue Mar 23, 2024 · 5 comments
Open

switch should be followed by a space #7906

hirasso opened this issue Mar 23, 2024 · 5 comments
Labels
kind/bug topic/whitespace Indentation, spacing, new lines

Comments

@hirasso
Copy link

hirasso commented Mar 23, 2024

Bug report

I just found a minor issue: PHP CS Fixer doesn't insert a space after the switch keyword, so this won't be fixed:

switch($value) {
    // ...
}

PHP_CodeSniffer's phpcbf fixes the missing space as expected:

switch ($value) {
    // ...
}

Description

Following the relevant paragraph in PSR-2, switch statements should be treated similarly to if statements and thus should be followed by a space.

Runtime version

PHP CS Fixer 3.52.1 15 Keys by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.2.0

Used command

vendor/bin/php-cs-fixer fix --config .php-cs-fixer.config.php --allow-risky=yes

Configuration file

<?php

$finder = PhpCsFixer\Finder::create()
    ->in([
        'public/content/themes/site',
    ])
    ->name('*.php')
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return (new PhpCsFixer\Config())
    ->setRules([
        '@PSR12' => true,
        '@PHP83Migration' => true,
        'no_unused_imports' => true,
    ])
    ->setFinder($finder);

Code snippet that reproduces the problem

switch($value) {
    // ...
}
@Wirone
Copy link
Member

Wirone commented Mar 23, 2024

@hirasso thanks for the report. Please use single_space_around_construct to achieve what you need 🙂.

The interesting part is why it's not a part of PSR-2, it's only included in @Symfony (and inherited in @PhpCsFixer). @keradus @julienfalque do you have historical context?

@Wirone Wirone added the topic/whitespace Indentation, spacing, new lines label Mar 23, 2024
@hirasso
Copy link
Author

hirasso commented Mar 23, 2024

Thanks so much for the pointer towards single_space_around_construct @Wirone !

How would I activate it? By just setting it to true in my config?

@Wirone
Copy link
Member

Wirone commented Mar 23, 2024

Well, it depends how you want it to work. As for any configurable rule you can use true for default config, or you can provide your own, using available options described in the docs.

@hirasso
Copy link
Author

hirasso commented Mar 23, 2024

Thank you, also for this amazingly quick reaction time ⚡️🙏

@keradus
Copy link
Member

keradus commented Mar 27, 2024

some context about ruleset: #4435 (comment)

probably set could be groomed, but we cannot add all constructs to PSR ruleset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug topic/whitespace Indentation, spacing, new lines
Projects
None yet
Development

No branches or pull requests

3 participants