schmunk42 / gii-template-collection

Gii Template Collection with code templates for models and CRUDs
https://github.com/schmunk42/gii-template-collection
51 stars 20 forks source link

generated code should be PSR-1 and -2 compliant #33

Open schmunk42 opened 11 years ago

schmunk42 commented 11 years ago

Code indent, formatting, etc....

motin commented 11 years ago

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

schmunk42 commented 11 years ago

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
motin commented 11 years ago

Fair enough, we'll do it manually.

motin commented 11 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

schmunk42 commented 10 years ago

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?

motin commented 10 years ago

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?

schmunk42 commented 10 years ago

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

cornernote commented 9 years ago

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

ucirello commented 8 years ago

Have you tried phpfmt/fmt ?

schmunk42 commented 8 years ago

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