ZeroOne3010/yetanotherhueapi

View on GitHub

Showing 21 of 67 total issues

File Hue.java has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package io.github.zeroone3010.yahueapi.v2;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Severity: Minor
Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.java - About 3 hrs to fix

    Hue has 24 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class Hue {
      private static final Logger logger = LoggerFactory.getLogger("io.github.zeroone3010.yahueapi");
      private static final int EXPECTED_NEW_LIGHTS_SEARCH_TIME_IN_SECONDS = 50;
      public static final String HUE_APPLICATION_KEY_HEADER = "hue-application-key";
      public static final long EVENTS_CONNECTION_TIMEOUT_MINUTES = 1L;
    Severity: Minor
    Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.java - About 2 hrs to fix

      UpdateLight has 23 methods (exceeds 20 allowed). Consider refactoring.
      Open

      @JsonInclude(JsonInclude.Include.NON_NULL)
      public class UpdateLight {
      
        @JsonProperty("on")
        private On on;

        MDNSResponseParser has 21 methods (exceeds 20 allowed). Consider refactoring.
        Open

        final class MDNSResponseParser {
          private static final Logger logger = LoggerFactory.getLogger(MDNSResponseParser.class);
        
          private static final int EXPECTED_QUESTION_COUNT = 0x01;
          private static final int EXPECTED_ANSWER_COUNT = 0x01;

          Method checkServerTrusted has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

            @Override
            public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
              try {
                trustManager.checkServerTrusted(chain, authType);
              } catch (final CertificateException exception) {

          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 refresh has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public void refresh() {
              try (final InputStream inputStream = getUrlConnection("").getInputStream()) {
                final ResourceRoot resourceRoot = objectMapper.readValue(inputStream, ResourceRoot.class);
                allResources = resourceRoot.getData().stream().collect(Collectors.toMap(r -> r.getId(), r -> r));
                logger.trace("Resource root: " + resourceRoot);
          Severity: Minor
          Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.java - About 1 hr to fix

            Method getNewLightsSearchStatus has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public NewLightsResult getNewLightsSearchStatus() {
            
                final JsonNode result;
                try {
                  result = objectMapper.readTree(new URL("https://" + bridgeIp + "/api/" + apiKey + "/lights/new"));
            Severity: Minor
            Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.java - About 1 hr to fix

              Method buildGroup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                public GroupImpl buildGroup(final GroupResource groupResource,
                                            final Map<UUID, Resource> allResources) {
                  final Supplier<Collection<Light>> lightProvider = () -> {
                    final Set<Light> deviceLights = groupResource.getChildren().stream()
                        .filter(r -> r.getResourceType() == DEVICE)
              Severity: Minor
              Found in src/main/java/io/github/zeroone3010/yahueapi/v2/GroupFactory.java - About 1 hr to fix

                Method checkServerTrusted has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  @Override
                  public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
                    try {
                      trustManager.checkServerTrusted(chain, authType);
                    } catch (final CertificateException exception) {

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

                    public static Color of(final Object otherColorObject) {
                      if (otherColorObject == null) {
                        throw new IllegalArgumentException("null cannot be parsed as a color.");
                      }
                  
                  
                  Severity: Minor
                  Found in src/main/java/io/github/zeroone3010/yahueapi/Color.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 getNewLightsSearchStatus has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                    public NewLightsResult getNewLightsSearchStatus() {
                  
                      final JsonNode result;
                      try {
                        result = objectMapper.readTree(new URL("https://" + bridgeIp + "/api/" + apiKey + "/lights/new"));
                  Severity: Minor
                  Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.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 initializeApiConnection has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    public CompletableFuture<String> initializeApiConnection(final String appName) {
                      final Supplier<String> apiKeySupplier = () -> {
                        final String body = "{\"devicetype\":\"yetanotherhueapi#" + appName + "\"}";
                        final URL baseUrl;
                        try {

                    Method discoverBridges has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      public Future<List<HueBridge>> discoverBridges(final Consumer<HueBridge> bridgeDiscoverer,
                                                                     final DiscoveryMethod... discoveryMethods) {
                        SecureJsonFactory factory = new SecureJsonFactory(null);
                        ObjectMapper objectMapper = factory.getCodec();
                        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

                      Method discoverBridges has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        @Override
                        public CompletableFuture<Void> discoverBridges() {
                          return CompletableFuture.supplyAsync(() -> {
                                try {
                                  startSocket();

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

                          public CompletableFuture<String> initializeApiConnection(final String appName) {
                            final Supplier<String> apiKeySupplier = () -> {
                              final String body = "{\"devicetype\":\"yetanotherhueapi#" + appName + "\"}";
                              final URL baseUrl;
                              try {

                        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 of has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          public static Color of(final Object otherColorObject) {
                            if (otherColorObject == null) {
                              throw new IllegalArgumentException("null cannot be parsed as a color.");
                            }
                        
                        
                        Severity: Minor
                        Found in src/main/java/io/github/zeroone3010/yahueapi/Color.java - About 1 hr to fix

                          Method subscribeToEvents has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            public HueEventSource subscribeToEvents(final HueEventListener eventListener) {
                              try {
                                SSLSocketFactory factory;
                                X509TrustManager trustManager;
                          
                          
                          Severity: Minor
                          Found in src/main/java/io/github/zeroone3010/yahueapi/v2/Hue.java - About 1 hr to fix

                            Method getString has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              private static String getString(final Function<URL, HttpsURLConnection> urlConnector,
                                                              final URL baseUrl,
                                                              final String path,
                                                              final String body,
                                                              final String method) {
                            Severity: Minor
                            Found in src/main/java/io/github/zeroone3010/yahueapi/v2/HttpUtil.java - About 35 mins to fix

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

                                @Override
                                protected InputStream _optimizedStreamFromURL(URL url) throws IOException {
                                  // This is the default JsonFactory check for files
                                  if ("file".equals(url.getProtocol())) {
                                    String host = url.getHost();
                              Severity: Minor
                              Found in src/main/java/io/github/zeroone3010/yahueapi/SecureJsonFactory.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 matchNames has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                private void matchNames(final List<String> expected) {
                                  final int questionNameLocation = bytePointer;
                                  while (true) {
                                    final int labelLength = data[bytePointer];
                                    bytePointer++;

                              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

                              Severity
                              Category
                              Status
                              Source
                              Language