php-cs-fixer - normalize array declaration

368 Views Asked by At

I have some code with array assignments that look like this:

$myArray['Data'] = [
    'stuff' => [
        'junk' => [
            'my_junk' => [
                'foo' => [
                    'the_goods' => 'some data!';
                ],
            ],
        ],
    ],
];

And other code that has arrays like this:

$otherArray['Data']['stuff']['junk']['other_junk'] = "data!";

What I want (and can't seem to find) is a php-cs-fixer rule (or other tool, if there's something more appropriate for the job) that normalizes the assignment levels themselves (not just changing the indentation or long vs short brace). In my favorite world, the result would be that both examples above end up as "flat" as possible:

$myArray['Data']['stuff']['junk']['my_junk']['foo']['the_goods'] = 'some data!';


$otherArray['Data']['stuff']['junk']['other_junk'] = "data!";

But I would settle for them both being expanded:

$myArray['Data'] = [
    'stuff' => [
        'junk' => [
            'my_junk' => [
                'foo' => [
                    'the_goods' => 'some data!';
                ],
            ],
        ],
    ],
];

$otherArray['Data'] = [
    'stuff' => [
        'junk' => [
            'other_junk' => "data!",
        ],
    ],
];

The end goal being that I could more easily identify differences between two arrays that are effectively the same, but were originally written level by level ( => [) versus using the shorthand notation ( [][] ).

0

There are 0 best solutions below