macgregor/alexandria

View on GitHub
alexandria-core/src/main/java/com/github/macgregor/alexandria/remotes/RemoteDocument.java

Summary

Maintainability
C
1 day
Test Coverage

File RemoteDocument.java has 257 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package com.github.macgregor.alexandria.remotes;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;

    Method doRequest has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected Response doRequest(Request request) throws HttpException {
            log.debug(request.toString());
            if(request.body() != null) {
                try {
                    log.debug(Requests.bodyToString(request));

      Method nextPage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              protected Iterator<T> nextPage() {
                  RemoteDocument remoteDocument = requestBuilder
                          .queryParameter(requestBuilder.pageSizeRequestParameter, pageSize.toString())
                          .queryParameter(requestBuilder.pageOffsetRequestParameter, offset.toString())
                          .build();

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

            protected Response doRequest(Request request) throws HttpException {
                log.debug(request.toString());
                if(request.body() != null) {
                    try {
                        log.debug(Requests.bodyToString(request));

        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

        Either remove or fill this block of code.
        Open

                    } catch (IOException e) {}

        Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

        Noncompliant Code Example

        for (int i = 0; i < 42; i++){}  // Empty on purpose or missing piece of code ?
        

        Exceptions

        When a block contains a comment, this block is not considered to be empty unless it is a synchronized block. synchronized blocks are still considered empty even with comments because they can still affect program flow.

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

                        throw new RuntimeException(e);

        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

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

                        throw new RuntimeException(new HttpException.Builder()

        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

        Provide the parametrized type for this generic.
        Open

                    RemoteDocument remoteDocument = requestBuilder

        Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.

        Noncompliant Code Example

        List myList; // Noncompliant
        Set mySet; // Noncompliant
        

        Compliant Solution

        List<String> myList;
        Set<? extends Number> mySet;
        

        Provide the parametrized type for this generic.
        Open

                    return new RemoteDocumentIterator(requestBuilder);

        Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.

        Noncompliant Code Example

        List myList; // Noncompliant
        Set mySet; // Noncompliant
        

        Compliant Solution

        List<String> myList;
        Set<? extends Number> mySet;
        

        Provide the parametrized type for this generic.
        Open

                return new RemoteDocumentPage(this.toBuilder());

        Generic types shouldn't be used raw (without type parameters) in variable declarations or return values. Doing so bypasses generic type checking, and defers the catch of unsafe code to runtime.

        Noncompliant Code Example

        List myList; // Noncompliant
        Set mySet; // Noncompliant
        

        Compliant Solution

        List<String> myList;
        Set<? extends Number> mySet;
        

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

            public T post(T t) throws HttpException {
                Request request = null;
                try {
                    request = Requests.requestBuilder(route(), headers)
                            .post(requestBody(t))
        alexandria-core/src/main/java/com/github/macgregor/alexandria/remotes/RemoteDocument.java on lines 149..167

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

        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 2 locations. Consider refactoring.
        Open

            public T put(T t) throws HttpException {
                Request request = null;
                try {
                    request = Requests.requestBuilder(route(), headers)
                            .put(requestBody(t))
        alexandria-core/src/main/java/com/github/macgregor/alexandria/remotes/RemoteDocument.java on lines 183..202

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

        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