Propel3 icon indicating copy to clipboard operation
Propel3 copied to clipboard

Use spaces instead of tabs for generated code.

Open marcj opened this issue 8 years ago • 2 comments

Currently the used library uses tabs, I guess hardcoded. We should make it configurable.

https://github.com/gossi/php-code-generator

See https://github.com/propelorm/Propel3/blob/e8e0db9161f6e5cb3ada49d88c80a042607286d2/src/Propel/Generator/Builder/Om/AbstractBuilder.php#L113

marcj avatar Jan 05 '17 18:01 marcj

The documentation of php-code-generator is saying

After generating code is finished, it can happen that (especially) bodies are formatted ugly. Thus just run the suggested code formatter after generating the code. Can be found on github gossi/php-code-formatter.

Well in the doc of php-code-formatter

Psr-2? Spaces suck, deal with it :p Once Version 1.0 is reached, a psr-2 profile will be shipped.

Last commit is 7 month ago - so - maybe we should replace simply "\t" with $n * " " where the replace and $n is configurable? But then the problem with ugly formatted code generated by php-code-generator will stay (as far as it exists).

Well, maybe a replacement of php-code-generator is another solution.

For Example zend-code It also has limited format options but a setIndentation() exists (defaults to 4 spaces). But the LF is set as a const to "\n". ZF3 uses PSR-2 so I assume that the generated code will follow PSR-2 (not tested)

demaggus83 avatar Jan 06 '17 09:01 demaggus83

I think the body is not an issue right now, since we have complete control over what is inside the body. Currently we use already spaces in there, however it gets indented with tabs (since you don't use indentation in the argument of ->setBody($code)).

I'm not sure where that tab is hardcoded, but maybe we can just subclass the generator/visitor that generates the actual code, replace it or make it configureable. Just replacing all \t could also be a way, although not so sexy.

marcj avatar Jan 06 '17 14:01 marcj