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
Fix coding style (static analysis) #95
Comments
|
I think this should be the first thing to do once 0.9 beta is released. There are several style fixers available, https://github.com/FriendsOfPHP/PHP-CS-Fixer is one. |
|
A good start would be to submit the PHP code to a static code analyzer (here's an article listing some). What is likely to be detected:
Benefits of static analysis:
How you can encourage devs to use it:
A first run of PHP Code Sniffer on Regarding code "fixers", I'm not a huge fan of having a tool altering a codebase by itself... sure, doing this by hand is tedious, but browsing your code is also a good way to spot bugs and inconsistencies (and learn things, too) :-) |
|
I agree that "fixer" changes are not easy to review, we should be wary of automatic linting tools. Thanks for pointing to PHP Code Sniffer, it's something that can definitely be done (it doesn't have to be done all at once, small improvements and patches are welcome). I'll have a look at it. |
|
A common usage is to fix warnings within / close to commit scopes, e.g.
This, or a "code cleanup rampage" sprint ;-) I should have some spare time in the upcoming weeks to look at this, plus #71; both being code-quality-related. |
|
Great suggestions. +1 for non-automatic changes (well, I guess I don't care
if it's automatic, as long as if it's not one big commit in git. If you
find a way to have an automatic tool change only one aspect at a time, it
makes it much more easy to review).
Having a Continuous Integration (e.g. TravisCI) would be great. When
submitting pull requests to Ampersand.js, I really like to see the messsage
indicating that the specific change hasn't yet been tested/passed CI
validation.
|
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to define dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to declare dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
Relates to shaarli#71 Relates to shaarli#95 Additions: - Makefile for easy usage, - Composer file to declare dev & test dependencies. Features: - PHP Copy/Paste Detect: detect duplicate code; - PHP Code Sniffer: static analysis, syntax checking, - PHP Mess Detector: static analysis, syntax checking. Signed-off-by: VirtualTam <virtualtam@flibidi.org>
|
I get a lot of these errors using php-cs. What is expected/how to fix this?
There is no comment on line 120... |
|
@nodiscc you just run make ? or something else? |
|
This warning points to the multi-line comment on lines 116-118, which may be associated by CodeSniffer with the function declaration at line 120: //==================================================================================================
// Checking session state (i.e. is the user still logged in)
//==================================================================================================
function setup_login_state() {
[...]
}which could be replaced by: /**
* Checking session state
*
* A bit more comments on what the function performs
*/
function setup_login_state() {
[...]
} |
|
Thanks @virtualtam, I will take care of these. Start small. |
|
You're welcome :) We can safely start with fixing:
This will remove a lot of noise from the output of code checkers, and help spot more important issues. (Bonus section) /**
* Brief description of the function
*
* Longer description of the function (optional):
* - it does this,
* - and that,
* - not to mention it's also good at doing this!
*
* @param $p1 Param description
* @param $p2 Param description
* @return What kind of object does the function return?
*/
function f($p1, $p2) {
[...]
} |
|
This one has become low priority for me (less time, reprioritizing issues). Anyone is free to work on it and submit a pull request (even small, partial fixes accepted) |
|
Yep, the PHPDoc checker is quite annoying and expects comments all over the place :D Given how the project has evolved since this issue was raised (3 years already!), I think code beautifiers could be run quite safely on all code that has unitary tests, so we can add PSR-2 checks to the CI pipeline. |
|
I've starting to work toward this. However note that PSR2 requires us to add a namespace to all classes, which should have be done at some point anyway. But it's a breaking change for 3rd parties. So it should be included in a new major. Could we include this in the |
Relates to shaarli#95 See: - https://github.com/squizlabs/PHP_CodeSniffer - https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist - https://www.php-fig.org/psr/psr-1/ - https://www.php-fig.org/psr/psr-2/ Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Relates to shaarli#95 See: - https://github.com/squizlabs/PHP_CodeSniffer - https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist - https://www.php-fig.org/psr/psr-1/ - https://www.php-fig.org/psr/psr-2/ Signed-off-by: VirtualTam <virtualtam@flibidi.net>
|
Relates to shaarli#95 See: - https://github.com/squizlabs/PHP_CodeSniffer - https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist - https://www.php-fig.org/psr/psr-1/ - https://www.php-fig.org/psr/psr-2/ Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Also temporarily ignore test code (one step at a time). Reference: https://www.php-fig.org/psr/psr-12/ Related to shaarli#95
Also temporarily ignore test code (one step at a time). Reference: https://www.php-fig.org/psr/psr-12/ Related to shaarli#95
A pass of an automatic coding style fixer may be needed to make shaarli more maintainable.
This will help find and trim down unnecessary complexity/broken code.
The text was updated successfully, but these errors were encountered: