ursinn/DeadByDaylightMC

View on GitHub
src/main/java/noahnok/dbdl/files/game/DArenaManager.java

Summary

Maintainability
C
1 day
Test Coverage

Method loadArenasFromFile has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public void loadArenasFromFile() {
        if (main.getArenasConfig().getConfig().get("arenas") == null) {
            return;
        }
        for (String key : main.getArenasConfig().getConfig().getConfigurationSection("arenas").getKeys(false)) {
Severity: Minor
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method loadArenasFromFile has 71 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public void loadArenasFromFile() {
        if (main.getArenasConfig().getConfig().get("arenas") == null) {
            return;
        }
        for (String key : main.getArenasConfig().getConfig().getConfigurationSection("arenas").getKeys(false)) {
Severity: Major
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 2 hrs to fix

Method getRandomArena has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public DArena getRandomArena() {
        List<DArena> tempArenaList = new ArrayList<>();
        for (DArena arena : arenas) {
            boolean hasDefault = false;
            for (DGamemode mode : arena.getUsableModes().keySet()) {
Severity: Minor
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method setUsableGamemodes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public void setUsableGamemodes(DArena a) {
        for (DGamemode mode : a.getUsableModes().keySet()) {
            if (a.getPossibleGeneratorLocations().size() < mode.getMaxgenerators()) {
                a.getUsableModes().put(mode, false);
                continue;
Severity: Minor
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method saveArenasToFile has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public void saveArenasToFile() {
        for (DArena arena : arenas) {
            String path = "arenas." + arena.getId() + ".";
            FileConfiguration config = main.getArenasConfig().getConfig();
            List<String> gamemodeStrings = new ArrayList<>();
Severity: Minor
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 1 hr to fix

Method setUsableGamemodes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public void setUsableGamemodes(DArena a) {
        for (DGamemode mode : a.getUsableModes().keySet()) {
            if (a.getPossibleGeneratorLocations().size() < mode.getMaxgenerators()) {
                a.getUsableModes().put(mode, false);
                continue;
Severity: Minor
Found in src/main/java/noahnok/dbdl/files/game/DArenaManager.java - About 1 hr to fix

Refactor this method to reduce its Cognitive Complexity from 25 to the 15 allowed.
Open

    public void loadArenasFromFile() {

Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

See

Define a constant instead of duplicating this literal "locations.exitGates." 6 times.
Open

                        String facing = (String) config.get(path + "locations.exitGates." + numb + ".facing");

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

public void run() {
  prepare("action1");                              // Noncompliant - "action1" is duplicated 3 times
  execute("action1");
  release("action1");
}

@SuppressWarning("all")                            // Compliant - annotations are excluded
private void method1() { /* ... */ }
@SuppressWarning("all")
private void method2() { /* ... */ }

public String method3(String a) {
  System.out.println("'" + a + "'");               // Compliant - literal "'" has less than 5 characters and is excluded
  return "";                                       // Compliant - literal "" has less than 5 characters and is excluded
}

Compliant Solution

private static final String ACTION_1 = "action1";  // Compliant

public void run() {
  prepare(ACTION_1);                               // Compliant
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Merge this if statement with the enclosing one.
Open

                    if (arena.getUsableModes().get(mode)) {

Merging collapsible if statements increases the code's readability.

Noncompliant Code Example

if (file != null) {
  if (file.isFile() || file.isDirectory()) {
    /* ... */
  }
}

Compliant Solution

if (file != null && isFileOrDirectory(file)) {
  /* ... */
}

private static boolean isFileOrDirectory(File file) {
  return file.isFile() || file.isDirectory();
}

Extract this nested try block into a separate method.
Open

                try {

Nesting try/catch blocks severely impacts the readability of source code because it makes it too difficult to understand which block will catch which exception.

There are no issues that match your filters.

Category
Status