Skip to content

WIP: Respect c:S1871 Two branches in a conditional structure should not have exactly the same implementation

I am of two minds about this one and have marked it as work in progress.

Nine of the state transitions have the same implementation (RSPEAK then GO_CLEAROBJ) and are flagged as duplicate code. This duplication is a classic maintenance problem. If these actions are intrinsically equivalent, then the code should be factored. (If they are coincidentally equivalent, then they shouldn't be factored.)

The obvious way to factor the code is to group the cases, as is suggested in this MR. However, this breaks the comforting treatment of the cases in numerical order, which makes it easy to check that all of the cases are handled, and “reads” like a table.

I think that the factoring proposed by this MR preserves the algorithm of the original, because the same state transitions are defined. But I understand that some might feel that defining them with a table was part of the original intent, and must be preserved.

https://sonarcloud.io/organizations/open-adventure/rules#rule_key=c%3AS1871

  • c:S1871 Two branches in a conditional structure should not have exactly the same implementation

Merge request reports