src/main/java/be/seeseemelk/mockbukkit/inventory/InventoryMock.java
Method addItem
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
public ItemStack addItem(ItemStack item)
{
item = item.clone();
for (int i = 0; i < items.length; i++)
{
- Read upRead up
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
Change the visibility of this constructor to "protected". Open
Open
public InventoryMock(InventoryHolder holder, int size, InventoryType type)
- Read upRead up
- Exclude checks
Abstract classes should not have public constructors. Constructors of abstract classes can only be called in constructors of their subclasses. So
there is no point in making them public. The protected
modifier should be enough.
Noncompliant Code Example
public abstract class AbstractClass1 { public AbstractClass1 () { // Noncompliant, has public modifier // do something here } }
Compliant Solution
public abstract class AbstractClass2 { protected AbstractClass2 () { // do something here } }