Hi,
I came across an issue where elements in array that are wrapped with double indentation, which isn't fixed by the fixer.
<?php
// expected
$var = array(
'a' => 1,
'b' => 2,
);
// actual
$var = array(
'a' => 1,
'b' => 2,
);
I've tried adding this case to the indentation fixer but it does not fail on unit test.
Can someone please verify or let me know it's not an issue?
Thanks.
Indentation fixer change tabs into spaces, it does not change level of indent.
There are no fixer that change indentation inside array
OK. That confirms my case. Is it worth building a fixer for it? If yes, should it be at contrib level?
If it change only indentation I would put it at Symfony level
OK. I'll read up on how to add a fixer during the holiday break. Thanks.
btw, remember about the following way of writing an array
$a = [
1 => 2, 5 => 6,
3 => 4, 7 => 8,
];
Also note that the correct indentation for double nested arrays in non-normalized form would be two levels deep here:
// correct
$var = array(array(
'a' => 1,
'b' => 2));
// and not
$var = array(array(
'a' => 1,
'b' => 2));
Would be nice if it could correct that, as well.
Note: The normalized form here would be:
// normalized
$var = array(
array(
'a' => 1,
'b' => 2
)
);
This matches the correct example above regarding indentation, so if any modification was made to the structure the 'a' => 1, line would not be affected by the changes, thus making the diff output smaller and more readable as only affected lines are included - which it should be when using proper indentation.
I was working on indentation fixer to only convert tabs to spaces, but also ensure every indent level is exactly 4 spaces.
I have something similar.
The code was having tabs and when I ran to convert to psr-2 it changed to spaces . But there is 8 spaces. See
return $this->render(
'AcmeShopBundle:Random:index.html.twig',
array(
'number' => $number
)
);
the above code is very ugly and it is unable to make it look nice :( .
Closing due to amazing work of #3135 by @julienfalque
Most helpful comment
Closing due to amazing work of #3135 by @julienfalque