Php-cs-fixer: short array fixer does not line break finally

Created on 17 Jan 2019  Â·  3Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

For configuration or updating questions please read the README and UPGRADE documentation,
or visit: https://gitter.im/PHP-CS-Fixer

When reporting an issue (bug) please provide the following information:

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

=> 7.2

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

=> 2.14.0

The command you use to run PHP CS Fixer:

=> vendor/bin/php

The configuration file you are using, if any:

$finder = PhpCsFixer\Finder::create()
    ->in('app')
    ->in('shell')
;

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules([
        '@Symfony' => true,
        'ordered_imports' => true,
        'no_unused_imports' => true,
        'psr0' => true,
        'array_syntax' => ['syntax' => 'short'],
        'no_superfluous_phpdoc_tags' => true,
        'linebreak_after_opening_tag' => true,
        'logical_operators' => true,
    ])
    ->setFinder($finder)
;

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

  • before running PHP CS Fixer (no changes):
<?php

class Foo
{
    public function export()
    {
        return array(
            'visits_keyword',
            'visits_count');
    }
}
  • with unexpected changes applied when running PHP CS Fixer:
<?php

class Foo
{
    public function export()
    {
        return [
            'visits_keyword',
            'visits_count', ];
    }
}
  • with the changes you expected instead:
<?php

class Foo
{
    public function export()
    {
        return [
            'visits_keyword',
            'visits_count',
        ];
    }
}

To be clear:

        return [
            'visits_keyword',
-            'visits_count', ];
+            'visits_count',
+       ]; 
kinfeature request

Most helpful comment

This is not the responsibility of array_syntax as that only switches between array() and [].

I don't think there currently is a fixer that does what you want.

All 3 comments

This is not the responsibility of array_syntax as that only switches between array() and [].

I don't think there currently is a fixer that does what you want.

Ok but couldn’t it be so hard to let the fixer do this?

couldn’t it be so hard to let the fixer do this?

It's not, but that is besides the point. Just like other code, fixers (should) follow the Single Responsibility Principle (SRP, the S in SOLID).

As I said before, the single responsibility of named fixer is to switch between syntax styles, and alignment has nothing to do with that, so it does not belong in that fixer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitek-rostislav picture vitek-rostislav  Â·  3Comments

kcloze picture kcloze  Â·  3Comments

aidantwoods picture aidantwoods  Â·  3Comments

EvgenyOrekhov picture EvgenyOrekhov  Â·  3Comments

grachevko picture grachevko  Â·  3Comments