prasadtalasila/BITS-Darshini

View on GitHub
src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.java

Summary

Maintainability
B
5 hrs
Test Coverage

Method parse has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static byte[] parse(byte[] header, int startBit, int endBit)
            throws IllegalArgumentException {

        // check if start and end bits are within the range of header
        int byteStartBit = 0;
Severity: Major
Found in src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.java - About 2 hrs to fix

Method parse has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public static byte[] parse(byte[] header, int startBit, int endBit)
            throws IllegalArgumentException {

        // check if start and end bits are within the range of header
        int byteStartBit = 0;
Severity: Minor
Found in src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.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 bitToByte has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    private static byte bitToByte(byte[] original, int lower, int higher,
            int extraBits, boolean reverse) {
Severity: Minor
Found in src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.java - About 35 mins to fix

Remove this expression which always evaluates to "true"
Open

        } else if (sbBoundary && !ebBoundary) {

If a boolean expression doesn't change the evaluation of the condition, then it is entirely unnecessary, and can be removed. If it is gratuitous because it does not match the programmer's intent, then it's a bug and the expression should be fixed.

Noncompliant Code Example

a = true;
if (a) { // Noncompliant
  doSomething();
}

if (b && a) { // Noncompliant; "a" is always "true"
  doSomething();
}

if (c || !a) { // Noncompliant; "!a" is always "false"
  doSomething();
}

Compliant Solution

a = true;
if (foo(a)) {
  doSomething();
}

if (b) {
  doSomething();
}

if (c) {
  doSomething();
}

See

Remove this expression which always evaluates to "true"
Open

        } else if (!sbBoundary && ebBoundary) {

If a boolean expression doesn't change the evaluation of the condition, then it is entirely unnecessary, and can be removed. If it is gratuitous because it does not match the programmer's intent, then it's a bug and the expression should be fixed.

Noncompliant Code Example

a = true;
if (a) { // Noncompliant
  doSomething();
}

if (b && a) { // Noncompliant; "a" is always "true"
  doSomething();
}

if (c || !a) { // Noncompliant; "!a" is always "false"
  doSomething();
}

Compliant Solution

a = true;
if (foo(a)) {
  doSomething();
}

if (b) {
  doSomething();
}

if (c) {
  doSomething();
}

See

Add a private constructor to hide the implicit public one.
Open

public class BitOperator {

Utility classes, which are collections of static members, are not meant to be instantiated. Even abstract utility classes, which can be extended, should not have public constructors.

Java adds an implicit public constructor to every class which does not define at least one explicitly. Hence, at least one non-public constructor should be defined.

Noncompliant Code Example

class StringUtils { // Noncompliant

  public static String concatenate(String s1, String s2) {
    return s1 + s2;
  }

}

Compliant Solution

class StringUtils { // Compliant

  private StringUtils() {
    throw new IllegalStateException("Utility class");
  }

  public static String concatenate(String s1, String s2) {
    return s1 + s2;
  }

}

Exceptions

When class contains public static void main(String[] args) method it is not considered as utility class and will be ignored by this rule.

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            for (int i = 0; i < fullBytes.length; i++) {
                returnBytes[i + 1] = fullBytes[i];
            }
src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.java on lines 145..147

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            for (int i = 0; i < fullBytes.length; i++) {
                returnBytes[i + 1] = fullBytes[i];
            }
src/main/java/in/ac/bits/protocolanalyzer/utils/BitOperator.java on lines 132..134

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 42.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

At-clause should have a non-empty description.
Open

     * @param b

At-clause should have a non-empty description.
Open

     * @param b

Local variable name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

            byte[] b = Arrays.copyOfRange(original, lower - 1, lower);

Checks that local, non-final variable names conform to a specified pattern.A catch parameter is considered to be a local variable.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Parameter name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

    public static int[] getBits(byte b) {

Checks that method parameter names conform to a specified pattern.By using accessModifiers property it is possibleto specify different formats for methods at different visibility levels.

To validate catch parameters please useCatchParameterName.

To validate lambda parameters please useLambdaParameterName.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

First sentence of Javadoc is missing an ending period.
Open

    /**

Checks thatJavadoc summary sentence does not contain phrases that are not recommended to use.Summaries that contain only the {@inheritDoc} tag are skipped. Check alsoviolate Javadoc that does not contain first sentence.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Parameter name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

    public static int getNibble(byte b, int nibbleIndex)

Checks that method parameter names conform to a specified pattern.By using accessModifiers property it is possibleto specify different formats for methods at different visibility levels.

To validate catch parameters please useCatchParameterName.

To validate lambda parameters please useLambdaParameterName.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

At-clause should have a non-empty description.
Open

     * @throws ArrayIndexOutOfBoundsException

At-clause should have a non-empty description.
Open

     * @param startBit

At-clause should have a non-empty description.
Open

     * @param index

At-clause should have a non-empty description.
Open

     * @param numberOfBits

First sentence of Javadoc is missing an ending period.
Open

    /**

Checks thatJavadoc summary sentence does not contain phrases that are not recommended to use.Summaries that contain only the {@inheritDoc} tag are skipped. Check alsoviolate Javadoc that does not contain first sentence.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

At-clause should have a non-empty description.
Open

     * @throws ArrayIndexOutOfBoundsException

At-clause should have a non-empty description.
Open

     * @param b

Parameter name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

    public static int getValue(byte b, int startBit, int numberOfBits)

Checks that method parameter names conform to a specified pattern.By using accessModifiers property it is possibleto specify different formats for methods at different visibility levels.

To validate catch parameters please useCatchParameterName.

To validate lambda parameters please useLambdaParameterName.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

At-clause should have a non-empty description.
Open

     * @throws ArrayIndexOutOfBoundsException

At-clause should have a non-empty description.
Open

     * @param nibbleIndex

Local variable name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

            byte[] b = Arrays.copyOfRange(original, higher, higher + 1);

Checks that local, non-final variable names conform to a specified pattern.A catch parameter is considered to be a local variable.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Parameter name 'b' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
Open

    public static int getBit(byte b, int index)

Checks that method parameter names conform to a specified pattern.By using accessModifiers property it is possibleto specify different formats for methods at different visibility levels.

To validate catch parameters please useCatchParameterName.

To validate lambda parameters please useLambdaParameterName.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Summary javadoc is missing.
Open

/**

Checks thatJavadoc summary sentence does not contain phrases that are not recommended to use.Summaries that contain only the {@inheritDoc} tag are skipped. Check alsoviolate Javadoc that does not contain first sentence.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

At-clause should have a non-empty description.
Open

     * @param b

First sentence of Javadoc is missing an ending period.
Open

    /**

Checks thatJavadoc summary sentence does not contain phrases that are not recommended to use.Summaries that contain only the {@inheritDoc} tag are skipped. Check alsoviolate Javadoc that does not contain first sentence.

This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.

Avoid if (x != y) ..; else ..;
Open

        if (!reverse) {
            // extra bits after higher boundary
            byte[] b = Arrays.copyOfRange(original, higher, higher + 1);
            int val = b[0];
            val = val >> (8 - extraBits);

ConfusingTernary

Since: PMD 1.9

Priority: Medium

Categories: Style

Remediation Points: 50000

Avoid negation within an 'if' expression with an 'else' clause. For example, rephrase: if (x != y) diff(); else same(); as: if (x == y) same(); else diff();. Most 'if (x != y)' cases without an 'else' are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, such as 'does the error case go first?' or 'does the common case go first?'.

Example:

boolean bar(int x, int y) {
 return (x != y) ? diff : same;
}

Avoid unnecessary if..then..else statements when returning booleans
Open

        if (target < lowerLimit || target > upperLimit) {
            return false;
        }

SimplifyBooleanReturns

Since: PMD 0.9

Priority: Medium

Categories: Style

Remediation Points: 50000

Avoid unnecessary if-then-else statements when returning a boolean. The result of the conditional test can be returned instead.

Example:

public boolean isBarEqualTo(int x) {
 if (bar == x) { // this bit of code...
 return true;
 } else {
 return false;
 }
}

public boolean isBarEqualTo(int x) {
 return bar == x; // can be replaced with this
}

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Open

public class BitOperator {

    /**
     * Returns the bit in byte b at the given index. Note that index must be
     * between 0-7

UseUtilityClass

Since: PMD 0.3

Priority: Medium

Categories: Style

Remediation Points: 50000

For classes that only have static methods, consider making them utility classes. Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods. Also, if you want this class to be a utility class, remember to add a private constructor to prevent instantiation. (Note, that this use was known before PMD 5.1.0 as UseSingleton).

Example:

public class MaybeAUtility {
 public static void foo() {}
 public static void bar() {}
}

There are no issues that match your filters.

Category
Status