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
Init rector config #6048
base: develop
Are you sure you want to change the base?
Init rector config #6048
Conversation
|
@@ -64,7 +64,7 @@ private function process(string $args = ''): int | |||
} | |||
|
|||
$commands = [ | |||
'cd ' . Yii::getAlias('@webroot'), | |||
'cd ' . Yii::getAlias('@config'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurabakhtin I like the fact that rector.php
is no longer in the root directory.
Maybe we can even move it to /protected/humhub/config
? Because /protected/config/
is more for custom configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome imitative, thank you! I've always tried to apply PHPCS&fixer. But there is hardly any clean file so far! :-) Does it make sense to make the following issue public/move it to this repo? |
@martin-rueegg It is not possible to publish private issues. But we can also discuss here. Currently, we had to put this issue on hold due to other work. But I hope that after the v.15 and other releases there will be more time for it... |
I see. No problem. Would it be an option to create a little bash script that runs a find over the source code tree and applies the current PHPCS Beautifier on all scripts? That would make it easier for now to adhere to at least some coding standards without changing any code (just layout). I'm using PhpStorm and have setup to run PhpCS automatically. For new files this is great. But every time I touch an existing file, it always finds some things that do not adhere to the standard. Having one script to run to fix all layout issues would be something that could be done by contributors or even added as a git hook. Could be a short term fix before rector comes into service? |
Yes, would be cool to have some beautifier tool configuration in the root. Which can be executed in the project folder or subfolders. Ideally with some GitHub Action support. But we really need to ensure to not break something, when touching so many files. I hope with Rector we can mainly optimizing/rewriting code (e.g. new PHP versions/deprecations) or add support for HumHub refactorings in modules. |
Actually, such a configuration already exits. It just does not seem to be enforced or even manually applied. Find errors with:
Fix fixable errors with:
Of course, the scripts can be configured with exclusions and stuff. But It would already help in getting rid of formatting issues. And I have not experienced that the automatically fixed errors would change the functioning of the code in any way. |
@martin-rueegg FYI, I just did some tests in the Commits:
Somehow we need to align the PHP_CodeSniffer to the PHPStorm format configuration. |
Hey @luke- that looks pretty cool. So basically, the two are not congruent in terms of indentation only. On roughly 22 lines of the entire codebase. I was not aware of a PhpStorm code style configuration. In fact, I was asking about in in this comment and since it was left without response, I thought there might be only the PHP_CodeSniffer configuration which made me turn off the codestyle in PhpStorm and only use the PHP PHP_CodeSniffer: I've also set to respect Would you be able to share your (Just for reference: [How to format complete project source code in phpstorm?](https://stackoverflow.com/questions/33697915/how-to-format-complete-project-source-code-in-phpstorm). Also, reformatting can happen before-commit.) |
@martin-rueegg I didn't made any changes to my PHPStorm code style configuration. Only few settings are loaded from the file in Git Probably, in cases of conflict, it would be best to find a solution that is acceptable to both tools. Example: PHPCS: <div>
<?= $form->field($model, 'dateInputDisplayFormat')->dropDownList([
// ...
]);
?>
</div> PHPStorm: <div>
<?= $form->field($model, 'dateInputDisplayFormat')->dropDownList([
// ...
]);
?>
</div> PHPStorm & PHPCS: <div>
<?= $form->field($model, 'dateInputDisplayFormat')->dropDownList([
// ...
]); ?>
</div> I did not know that it is also possible to format the code via PHPStorm using PHPCS. Theoretically, we could also just require this setting from the developers and enforce this via GitHub Action. Of course, I would prefer if both tools PHPStorm & PHPCS produce the identical output. Then you wouldn't be limited to one tool. Do you know any other tools for automatic PHP formatting? |
Ok, could you please share the configuration anyway, just to make sure we're having the same starting point. Could you maybe export your config (in Settings / Editor / Code Style / PHP - using the cog wheel next to the Scheme selection)
This might be a tricky task, as not everything can be configured, in my experience. Since IDEs can vary and php scripts can be executed by any developer, I would opt for an authoritative code style fixer which can be run from the console and hence tested/verified/applied through git hooks or actions. Additional nice-to-haves could be set in the IDE. Hence, in the case of conflict, the external php formatter would win. Most IDE's can be configured to run those and they will overwrite the internals settings.
In the dev docs we could add a description on how to do that. We could also include respective settings in the code base (e.g.
That would be my recommendation, see above.
I don't think it's such a big deal, given that the external formatter has precedence.
Not extensively. I have my own personal code style for my own projects, that uses a lot of new lines to give space to the eye and make visual navigation easier and source code versioning more atomic. I use the PhpStorm for this. However, I've also been working with but don't have enough experience to make an informed recommendation. At one customer the PHP_CodeSniffer would even prevent a commit before it's fixed. |
The reason why I'm asking for your exact standards is, that after checking out
and then running
I still ended up with
202 files of which are messages, replacing the array notation. The rest is in migrations and tests. Did you exclude those? Although, most changes are just adding/removing empty lines. And adding brackets after |
|
What kind of change does this PR introduce? (check at least one)
The PR fulfills these requirements:
develop
branch, not themaster
branch if no hotfixOther information:
https://github.com/humhub/team_tasks/issues/271