schmunk42/gii-template-collection

generated code should be PSR-1 and -2 compliant

Opened this issue · 13 comments

Code indent, formatting, etc....

We can run it through http://cs.sensiolabs.org

I just tried it on the outputted files, but it doesn't support re-indentation atm.
So I think we'll have to fix the generator manually.

Tried with:

php-cs-fixer.phar fix . --fixers=linefeed,short_tag,indentation
php-cs-fixer.phar fix . --level=psr2

Fair enough, we'll do it manually.

Most it is now done through cfdd0e9 and e43ff00

A question regarding formatting that is not covered under PSR2:

The current code has a lot of this style of formatting:
array('foo'=>'bar')

PhpStorm's default setting for Assignment Operators is to leave spaces around them:
array('foo' => 'bar')

I'd like to use this default style in the generated code. What do you think about that?

A similar default style setting is to have a space after commas so that this:
$foo = bar($a,$b);
$arr = array(0 => "zero",1 => "one");

..becomes:
$foo = bar($a, $b);
$arr = array(0 => "zero", 1 => "one");

Should we also here use PhpStorm's default setting (the latter)?

I however vote for changing these default PhpStorm settings:

Function call arguments - From "Chop down if long" to "Do not wrap"
New line after '(' - From checked to unchecked
Place ')' on new line - From checked to unchecked

And the same for Array initializer

This is fine:

$foo = bar($a, $b);
$arr = array(0 => "zero", 1 => "one");
array('foo' => 'bar')

Could you give me some examples for the other cases?

Check out 3991312, 7f5a389 and 8ea9727

Could you give me some examples for the other cases?

Do you mean the code not formatted as per above, or are you referring to the "Do not wrap" settings?

Found this script: http://stackoverflow.com/a/494295/291573 (32 upvotes)
and this one: http://pear.php.net/package/PHP_Beautifier (inactive)

Indentation fixer change tabs into spaces, it does not change level of indent.
There are no fixer that change indentation inside array
PHP-CS-Fixer/PHP-CS-Fixer#770

Have you tried phpfmt/fmt ?

@ccirello No, not yet - but looks promising, thank you.
I tried https://github.com/cmrcx/phptidy for https://github.com/schmunk42/yii2-giiant