Php-cs-fixer: remove multiple spaces between function parameter's type hint and name

Created on 7 May 2018  Â·  1Comment  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

The PHP version you are using ($ php -v):

=> 7.2.2

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> 2.11.1

The command you use to run PHP CS Fixer:

=> using vscode extension: junstyle/vscode-php-cs-fixer

The configuration file you are using, if any:

<?php

return PhpCsFixer\Config::create()
    ->setRules([
        '@Symfony' => true,

        // There should not be an empty return statement at the end of a function.
        'no_useless_return' => true,

        // Pre- or post-increment and decrement operators should be used if possible.
        'increment_style' => ['style' => 'post'],

        // PHP arrays should be declared using the configured syntax.
        'array_syntax' => ['syntax' => 'short'],

        // A return statement wishing to return void should not return null.
        'simplified_null_return' => true,

        // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
        'multiline_whitespace_before_semicolons' => true,

        // Convert double quotes to single quotes for simple strings.
        'single_quote' => ['strings_containing_single_quote_chars' => true],

        // Ordering use statements.
        'ordered_imports' => true,

        // There should not be any empty comments.
        'no_empty_comment' => false,

        // There should not be empty PHPDoc blocks.
        'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal']],

        // A single space or none should be between cast and variable.
        'cast_spaces' => ['space' => 'none'],

        // @return void and @return null annotations should be omitted from PHPDocs.
        'phpdoc_no_empty_return' => false,

        // Remove extra spaces in a nullable typehint.
        'compact_nullable_typehint' => true,
    ])
    ->setLineEnding("\n");

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
public static function Foo(string        $arg1, bool        $arg2)
{
    return        true;
}
  • with unexpected changes applied when running PHP CS Fixer:
public static function Foo(string        $arg1, bool        $arg2)
{
    return        true;
}
  • with the changes you expected instead:
public static function Foo(string $arg1, bool $arg2)
{
    return true;
}

spaces between string and $arg1, spaces between bool and $arg2, spaces between return and true.

Is there such rule that I'm unaware of?

kinfeature request

Most helpful comment

:+1: for

-function Foo(string        $arg1, bool        $arg2)
+function Foo(string $arg1, bool $arg2)

for removing spaces spaces after return statement - why only after return? why not after throw as well? or anything else? IMO not well defined and definitely that would be different rule, let us focus on space between param type and param name first

>All comments

:+1: for

-function Foo(string        $arg1, bool        $arg2)
+function Foo(string $arg1, bool $arg2)

for removing spaces spaces after return statement - why only after return? why not after throw as well? or anything else? IMO not well defined and definitely that would be different rule, let us focus on space between param type and param name first

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  Â·  3Comments

UksusoFF picture UksusoFF  Â·  3Comments

kcloze picture kcloze  Â·  3Comments

grachevko picture grachevko  Â·  3Comments

EvgenyOrekhov picture EvgenyOrekhov  Â·  3Comments