-
Notifications
You must be signed in to change notification settings - Fork 80
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
[EC2][PHP][5R] Avoid Multiple IfElse Statements #160
Conversation
php-plugin/src/main/resources/fr/greencodeinitiative/l10n/php/rules/custom/EC2.html
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! |
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.
please add also updates with this rule implementation :
CHANGELOG.md
: add issue linkRULES.md
: change icon
another modification to do : add a tests in ecoCode-php-test-project ==> please check others tests and make the same. as you can see test files are quite identical to unit test resources files
please make corrections on code smell problems (sonarcloud report)
...lugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java
Show resolved
Hide resolved
|
||
private void checkElseIfStatement(Tree tree) { | ||
String ifTree = tree.toString(); | ||
String findStr = "elseif"; |
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.
here, you find only elseif
use casees but you can have else
and if
separated use case, and they won't be found.
} | ||
BlockTree node = (BlockTree) parentNode; | ||
int sizeBody = node.statements().toArray().length; | ||
for(int i=0; i<sizeBody;++i){ |
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.
the algorithm can be optimized :
- you can use streams
- you can use a loop and break it once count > 1, instead of loop on all elements for nothing
- you can use
foreach
loop insteadfor
loop, it should be more accurate
|
||
<h2>Non-compliant Code Example</h2> | ||
<pre> | ||
$index = 1; |
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.
please correct indentation
} | ||
} | ||
|
||
public function methodWithOneIfElseIf() { |
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.
please add another method test with separated else
and if
instead of elseif
...lugin/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java
Show resolved
Hide resolved
Hi @eliottlv,
... in ordre to merge this PR. |
new PR #200 created to make the review modifications ourselves (because of inactivity) PR closed due to recreation a local branch to edit code (because of inactivity in this PR) |
Issue #121