Method signInteract
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
@EventHandler
public void signInteract(PlayerInteractEvent e) {
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
if (e.getClickedBlock().getType().equals(Material.SIGN) ||
e.getClickedBlock().getType().equals(Material.WALL_SIGN)) {
- Read upRead up
- Create a ticketCreate a ticket
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
Avoid deeply nested control flow statements. Open
if (main.getSignManager().getSign(e.getClickedBlock()).getGame() != null) {
if (main.getSignManager().getSign(e.getClickedBlock()).getGame().equals(
main.getGameManager().getGamePlayerIsIn(e.getPlayer()))) {
e.getPlayer().sendMessage("You are already in a game!");
return;
- Create a ticketCreate a ticket
Method signBreakEvent
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
@EventHandler
public void signBreakEvent(BlockBreakEvent e) {
if (e.getBlock().getType().equals(Material.SIGN) || e.getBlock().getType().equals(Material.WALL_SIGN)) {
if (((Sign) e.getBlock().getState()).getLine(0).equals(signLine)) {
if (e.getPlayer().hasPermission("dbdl.sign.break")) {
- Read upRead up
- Create a ticketCreate a ticket
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
Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed. Open
public void signInteract(PlayerInteractEvent e) {
- 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
Merge this if statement with the enclosing one. Open
if (main.getSignManager().getSign(e.getClickedBlock()) != null) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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(); }
Merge this if statement with the enclosing one. Open
if (((Sign) e.getBlock().getState()).getLine(0).equals(signLine)) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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(); }
Merge this if statement with the enclosing one. Open
if (e.getClickedBlock().getType().equals(Material.SIGN) ||
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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(); }
Merge this if statement with the enclosing one. Open
if (e.getLine(1).equalsIgnoreCase("join")) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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(); }
Merge this if statement with the enclosing one. Open
if (main.getSignManager().getSign(e.getClickedBlock()).getGame() != null) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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(); }