LoboEvolution/LoboEvolution

View on GitHub
LoboCommon/src/main/java/org/loboevolution/common/Strings.java

Summary

Maintainability
C
1 day
Test Coverage

Strings has 26 methods (exceeds 20 allowed). Consider refactoring.
Open

public final class Strings {

    /** The Constant EMPTY_ARRAY. */
    public static final String[] EMPTY_ARRAY = new String[0];

Severity: Minor
Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 3 hrs to fix

    Method split has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public static String[] split(final String phrase) {
            final ArrayList<String> wordList = new ArrayList<>();
            StringBuilder word = null;
            final char[] list = phrase.toCharArray();
            for (final char ch : list) {
    Severity: Minor
    Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.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 strictHtmlEncode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static String strictHtmlEncode(final String rawText, final boolean quotes) {
            final StringBuilder output = new StringBuilder();
            final char[] list = rawText.toCharArray();
            for (final char ch : list) {
                switch (ch) {
    Severity: Minor
    Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 1 hr to fix

      Method split has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static String[] split(final String phrase) {
              final ArrayList<String> wordList = new ArrayList<>();
              StringBuilder word = null;
              final char[] list = phrase.toCharArray();
              for (final char ch : list) {
      Severity: Minor
      Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-') {
                        continue;
                    }
        Severity: Major
        Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 1 hr to fix

          Method splitIgnoreCase has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public static String[] splitIgnoreCase(final String text, final String text1) {
                  if (text != null && text1 != null) {
                      return text.split(text1.toLowerCase()).length > 1 ? text.split(text1.toLowerCase()) :
                              text.split(text1.toUpperCase()).length > 1 ? text.split(text1.toUpperCase()) : new String[]{};
                  }
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 35 mins 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 strictHtmlEncode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public static String strictHtmlEncode(final String rawText, final boolean quotes) {
                  final StringBuilder output = new StringBuilder();
                  final char[] list = rawText.toCharArray();
                  for (final char ch : list) {
                      switch (ch) {
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 35 mins 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 trimForAlphaNumDash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public static String trimForAlphaNumDash(final String rawText) {
                  final char[] list = rawText.toCharArray();
                  int index = 0;
                  for (final char ch : list) {
                      index++;
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java - About 35 mins 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

          Merge this if statement with the enclosing one.
          Open

                      if (text.charAt(0) == '"' && text.charAt(length - 1) == '"') {

          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 ternary operation into an independent statement.
          Open

                              text.split(text1.toUpperCase()).length > 1 ? text.split(text1.toUpperCase()) : new String[]{};

          Just because you can do something, doesn't mean you should, and that's the case with nested ternary operations. Nesting ternary operators results in the kind of code that may seem clear as day when you write it, but six months later will leave maintainers (or worse - future you) scratching their heads and cursing.

          Instead, err on the side of clarity, and use another line to express the nested operation as a separate statement.

          Noncompliant Code Example

          public String getReadableStatus(Job j) {
            return j.isRunning() ? "Running" : j.hasErrors() ? "Failed" : "Succeeded";  // Noncompliant
          }
          

          Compliant Solution

          public String getReadableStatus(Job j) {
            if (j.isRunning()) {
              return "Running";
            }
            return j.hasErrors() ? "Failed" : "Succeeded";
          }
          

          Define and throw a dedicated exception instead of using a generic one.
          Open

              public static String hash(final String password, final byte[] salt) throws Exception {

          Using such generic exceptions as Error, RuntimeException, Throwable, and Exception prevents calling methods from handling true, system-generated exceptions differently than application-generated errors.

          Noncompliant Code Example

          public void foo(String bar) throws Throwable {  // Noncompliant
            throw new RuntimeException("My Message");     // Noncompliant
          }
          

          Compliant Solution

          public void foo(String bar) {
            throw new MyOwnRuntimeException("My Message");
          }
          

          Exceptions

          Generic exceptions in the signatures of overriding methods are ignored, because overriding method has to follow signature of the throw declaration in the superclass. The issue will be raised on superclass declaration of the method (or won't be raised at all if superclass is not part of the analysis).

          @Override
          public void myMethod() throws Exception {...}
          

          Generic exceptions are also ignored in the signatures of methods that make calls to methods that throw generic exceptions.

          public void myOtherMethod throws Exception {
            doTheThing();  // this method throws Exception
          }
          

          See

          Merge this if statement with the enclosing one.
          Open

                      if ((text.charAt(0) == '\'') && (text.charAt(length - 1) == '\'')) {

          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();
          }
          

          Return an empty array instead of null.
          Open

                  return null;

          Returning null instead of an actual array or collection forces callers of the method to explicitly test for nullity, making them more complex and less readable.

          Moreover, in many cases, null is used as a synonym for empty.

          Noncompliant Code Example

          public static List<Result> getResults() {
            return null;                             // Noncompliant
          }
          
          public static Result[] getResults() {
            return null;                             // Noncompliant
          }
          
          public static void main(String[] args) {
            Result[] results = getResults();
          
            if (results != null) {                   // Nullity test required to prevent NPE
              for (Result result: results) {
                /* ... */
              }
            }
          }
          

          Compliant Solution

          public static List<Result> getResults() {
            return Collections.emptyList();          // Compliant
          }
          
          public static Result[] getResults() {
            return new Result[0];
          }
          
          public static void main(String[] args) {
            for (Result result: getResults()) {
              /* ... */
            }
          }
          

          See

          • CERT, MSC19-C. - For functions that return an array, prefer returning an empty array over a null value
          • CERT, MET55-J. - Return an empty array or collection instead of a null value for methods that return an array or collection

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              public static boolean containsIgnoreCase(final String text, final String text1) {
                  return text != null && text1 != null && (text.contains(text1.toLowerCase()) || text.contains(text1.toUpperCase()));
              }
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java and 2 other locations - About 35 mins to fix
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 134..136
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 138..140

          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 43.

          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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              public static boolean endsWithIgnoreCase(final String text, final String text1) {
                  return text != null && text1 != null && (text.endsWith(text1.toLowerCase()) || text.endsWith(text1.toUpperCase()));
              }
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java and 2 other locations - About 35 mins to fix
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 130..132
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 134..136

          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 43.

          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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              public static boolean startsWithIgnoreCase(final String text, final String text1) {
                  return text != null && text1 != null && (text.startsWith(text1.toLowerCase()) || text.startsWith(text1.toUpperCase()));
              }
          Severity: Minor
          Found in LoboCommon/src/main/java/org/loboevolution/common/Strings.java and 2 other locations - About 35 mins to fix
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 130..132
          LoboCommon/src/main/java/org/loboevolution/common/Strings.java on lines 138..140

          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 43.

          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

          There are no issues that match your filters.

          Category
          Status