gii-template-collection icon indicating copy to clipboard operation
gii-template-collection copied to clipboard

generated code should be PSR-1 and -2 compliant

Open schmunk42 opened this issue 12 years ago • 13 comments

Code indent, formatting, etc....

schmunk42 avatar Jul 14 '13 22:07 schmunk42

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

motin avatar Jul 14 '13 22:07 motin

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

schmunk42 avatar Jul 15 '13 16:07 schmunk42

Fair enough, we'll do it manually.

motin avatar Jul 16 '13 00:07 motin

Most it is now done through https://github.com/schmunk42/gii-template-collection/commit/cfdd0e9e781b4181569cce151f70622e9add5ae9 and https://github.com/schmunk42/gii-template-collection/commit/e43ff00a9d3d8421d62bbdcd30f1251710a47c24

motin avatar Jul 29 '13 09:07 motin

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?

motin avatar Sep 23 '13 14:09 motin

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)?

motin avatar Sep 23 '13 14:09 motin

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

motin avatar Sep 23 '13 15:09 motin

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?

schmunk42 avatar Sep 23 '13 18:09 schmunk42

Check out 39913128239f14a02473ef2ecfbda4a958a70d6b, 7f5a389a3d2c9e14909602e6cdf7e64be08f8a6b and 8ea9727d79536a9cacabda24bfcb173c2186f075

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?

motin avatar Sep 24 '13 10:09 motin

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

schmunk42 avatar Sep 24 '13 23:09 schmunk42

Indentation fixer change tabs into spaces, it does not change level of indent. There are no fixer that change indentation inside array https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/770

cornernote avatar May 28 '15 06:05 cornernote

Have you tried phpfmt/fmt ?

ucirello avatar Feb 01 '16 15:02 ucirello

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

schmunk42 avatar Feb 01 '16 19:02 schmunk42