mizo0203/nature-remo-sample

View on GitHub

Showing 13 of 30 total issues

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

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_1:
                mPresenter.sendButtonEvent(RemoteControlButtonType.NUM_1);
Severity: Major
Found in app/src/main/java/com/mizo0203/natureremoapisample/MainFragment.java - About 2 hrs to fix

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

        public static class ApplianceModel {
            public final String id;
            public final String manufacturer;
            public final String remote_name;
            public final String name;
    app/src/main/java/com/mizo0203/natureremoapisample/data/Appliance.java on lines 79..93

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

    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 static class AirConParams {
            public final String temp;
            public final String mode;
            public final String vol;
            public final String dir;
    app/src/main/java/com/mizo0203/natureremoapisample/data/Appliance.java on lines 63..77

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

    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

    package com.mizo0203.natureremoapisample.data;
    
    public class IRSignal {
    
        /**
    app/src/main/java/com/mizo0203/natureremoapisample/data/Signal.java on lines 1..29

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

    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

    /*
     * Copyright 2018, Satoki Mizoguchi
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
    app/src/main/java/com/mizo0203/natureremoapisample/data/IRSignal.java on lines 1..39

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

    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

    Do not hard code the IP address
    Open

        private static final String NATURE_REMO_IP_ADDRESS = "192.168.1.23";

    AvoidUsingHardCodedIP

    Since: PMD 4.1

    Priority: Medium

    Categories: Style

    Remediation Points: 50000

    Application with hard-coded IP addresses can become impossible to deploy in some cases. Externalizing IP adresses is preferable.

    Example:

    public class Foo {
     private String ip = '127.0.0.1'; // not recommended
    }

    Move constants defined in this interfaces to another class or enum.
    Open

    public interface RemoteControlButtonType {

    According to Joshua Bloch, author of "Effective Java":

    The constant interface pattern is a poor use of interfaces.

    That a class uses some constants internally is an implementation detail.

    Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface,

    all of its subclasses will have their namespaces polluted by the constants in the interface.

    This rule raises an issue when an interface consists solely of fields, without any other members.

    Noncompliant Code Example

    interface Status {                      // Noncompliant
       int OPEN = 1;
       int CLOSED = 2;
    }
    

    Compliant Solution

    public enum Status {                    // Compliant
      OPEN,
      CLOSED;
    }
    

    or

    public final class Status {             // Compliant
       public static final int OPEN = 1;
       public static final int CLOSED = 2;
    }
    

    Constructor has 9 parameters, which is greater than 7 authorized.
    Open

        public Appliance(String id, DeviceCore device, ApplianceModel model, String nickname, String image, String type, AirConParams settings, AirCon aircon, Signal[] signals) {

    A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

    Noncompliant Code Example

    With a maximum number of 4 parameters:

    public void doSomething(int param1, int param2, int param3, String param4, long param5) {
    ...
    }
    

    Compliant Solution

    public void doSomething(int param1, int param2, int param3, String param4) {
    ...
    }
    

    Exceptions

    Methods annotated with :

    • Spring's @RequestMapping (and related shortcut annotations, like @GetRequest)
    • JAX-RS API annotations (like @javax.ws.rs.GET)
    • Bean constructor injection with @org.springframework.beans.factory.annotation.Autowired
    • CDI constructor injection with @javax.inject.Inject
    • @com.fasterxml.jackson.annotation.JsonCreator

    may have a lot of parameters, encapsulation being possible. Such methods are therefore ignored.

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

    public class Injection {

    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.

    Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
    Open

        public void start() {

    There are several reasons for a method not to have a method body:

    • It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production.
    • It is not yet, or never will be, supported. In this case an UnsupportedOperationException should be thrown.
    • The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.

    Noncompliant Code Example

    public void doSomething() {
    }
    
    public void doSomethingElse() {
    }
    

    Compliant Solution

    @Override
    public void doSomething() {
      // Do nothing because of X and Y.
    }
    
    @Override
    public void doSomethingElse() {
      throw new UnsupportedOperationException();
    }
    

    Exceptions

    Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.

    public abstract class Animal {
      void speak() {  // default implementation ignored
      }
    }
    

    T is not used in the method.
    Open

        private <T> Callback<T> createCallback(final NatureRemoRepository.Callback<T> callback) {

    Type parameters that aren't used are dead code, which can only distract and possibly confuse developers during maintenance. Therefore, unused type parameters should be removed.

    Noncompliant Code Example

    int <T> Add(int a, int b) // Noncompliant; <T> is ignored
    {
      return a + b;
    }
    

    Compliant Solution

    int Add(int a, int b)
    {
      return a + b;
    }
    

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

    public class ActivityUtils {

    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.

    Move the contents of this initializer to a standard constructor or to field initializers.
    Open

                {

    Non-static initializers are rarely used, and can be confusing for most developers because they only run when new class instances are created. When possible, non-static initializers should be refactored into standard constructors or field initializers.

    Noncompliant Code Example

    class MyClass {
      private static final Map<String, String> MY_MAP = new HashMap<String, String>() {
    
        // Noncompliant - HashMap should be extended only to add behavior, not for initialization
        {
          put("a", "b");
        }
    
      };
    }
    

    Compliant Solution

    class MyClass {
      private static final Map<String, String> MY_MAP = new HashMap<String, String>();
    
      static {
        MY_MAP.put("a", "b");
      }
    }
    

    or using Java 9 Map.of:

    class MyClass {
      // Compliant
      private static final Map<String, String> MY_MAP = java.util.Map.of("a", "b");
    }
    

    or using Guava:

    class MyClass {
      // Compliant
      private static final Map<String, String> MY_MAP = ImmutableMap.of("a", "b");
    }
    
    Severity
    Category
    Status
    Source
    Language