Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spaces instead of tabs for generated code. #4

Open
marcj opened this issue Jan 5, 2017 · 2 comments
Open

Use spaces instead of tabs for generated code. #4

marcj opened this issue Jan 5, 2017 · 2 comments

Comments

@marcj
Copy link
Member

marcj commented Jan 5, 2017

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

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

See

$code = "<?php\n\n" . $generator->generate($this->getDefinition());

@marcj marcj added the easy pick label Jan 5, 2017
@demaggus83
Copy link
Contributor

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)

@marcj
Copy link
Member Author

marcj commented Jan 6, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants