src/main/java/com/github/joshj1091/mcserver/MCServer.java
Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. Open
Open
public MCServer() throws IOException {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
Remove this assignment of "instance". Open
Open
instance = this;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Assigning a value to a static
field in a constructor could cause unreliable behavior at runtime since it will change the value for all
instances of the class.
Instead remove the field's static
modifier, or initialize it statically.
Noncompliant Code Example
public class Person { static Date dateOfBirth; static int expectedFingers; public Person(date birthday) { dateOfBirth = birthday; // Noncompliant; now everyone has this birthday expectedFingers = 10; // Noncompliant } }
Compliant Solution
public class Person { Date dateOfBirth; static int expectedFingers = 10; public Person(date birthday) { dateOfBirth = birthday; } }