milosmns/silly-android

View on GitHub
sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java

Summary

Maintainability
C
1 day
Test Coverage

File Coloring.java has 434 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

package me.angrybyte.sillyandroid.extras;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;

    Coloring has 29 methods (exceeds 20 allowed). Consider refactoring.
    Wontfix

    @SuppressWarnings({"WeakerAccess", "unused"})
    public final class Coloring {
    
        /**
         * Used as a bounds side when no drawable bounds are supplied within the original drawable

      Method createStateList has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

          @NonNull
          public static StateListDrawable createStateList(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
                                                          @ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius) {
              // initialize state arrays (they're in arrays because you can use different drawables for reverse transitions..)
              final int[] normalState = new int[]{};

        Method createMultiStateDrawable has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Wontfix

            @NonNull
            public static StateListDrawable createMultiStateDrawable(@NonNull final Drawable normalDrawable, @NonNull final Drawable clickedDrawable,
                                                                     @NonNull final Drawable checkedDrawable, final boolean shouldFade) {
                // migrate to static drawables
                Drawable normalState = normalDrawable;

          Method createContrastStateDrawable has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Wontfix

              @NonNull
              public static StateListDrawable createContrastStateDrawable(@NonNull final Context context, @ColorInt final int normalColor, @ColorInt final int
                      pressedBackColor,
                                                                          final boolean shouldFade, @NonNull final Drawable original) {
                  // migrate to a static drawable

            Method decodeColor has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Invalid

                @ColorInt
                public static int decodeColor(@NonNull final String hexValue) {
                    if (SillyAndroid.isEmpty(hexValue)) {
                        return Color.DKGRAY;
                    }

              Method createResponsiveDrawable has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Invalid

                  public static Drawable createResponsiveDrawable(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
                                                                  @ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius,
                                                                  @Nullable final Rect bounds) {

                Method createResponsiveDrawable has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Invalid

                    public static Drawable createResponsiveDrawable(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
                                                                    @ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius) {

                  Method createStateList has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Invalid

                      public static StateListDrawable createStateList(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
                                                                      @ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius) {

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

                        public static StateListDrawable createContrastStateDrawable(@NonNull final Context context, @ColorInt final int normalColor, @ColorInt final int
                                pressedBackColor,
                                                                                    final boolean shouldFade, @NonNull final Drawable original) {

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

                          @NonNull
                          public static Drawable colorUnknownDrawable(@NonNull final Drawable drawable, @ColorInt final int color) {
                              // check if this is a drawable wrapper, then do coloring by drawable wrapping
                              final boolean isDrawableWrapperPlatform;
                              isDrawableWrapperPlatform = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && drawable instanceof DrawableWrapper;

                      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

                      Avoid too many return statements within this method.
                      Open

                                  return new BitmapDrawable(context.getResources(), colorBitmap(bitmap, color));

                        Avoid too many return statements within this method.
                        Open

                                return colorUnknownDrawable(drawable, color);

                          Method createStateList has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Invalid

                              @NonNull
                              public static StateListDrawable createStateList(@NonNull final Context context, @ColorInt final int normal, @ColorInt final int clicked,
                                                                              @ColorInt final int checked, final boolean shouldFade, @IntRange(from = 0) int cornerRadius) {
                                  // initialize state arrays (they're in arrays because you can use different drawables for reverse transitions..)
                                  final int[] normalState = new int[]{};

                          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 createRippleDrawable has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @NonNull
                              @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
                              public static RippleDrawable createRippleDrawable(@ColorInt final int normalColor, @ColorInt final int rippleColor, @Nullable final Rect bounds,
                                                                                @IntRange(from = 0) final int cornerRadius) {
                                  Drawable maskDrawable = null;

                          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 decodeColor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @ColorInt
                              public static int decodeColor(@NonNull final String hexValue) {
                                  if (SillyAndroid.isEmpty(hexValue)) {
                                      return Color.DKGRAY;
                                  }

                          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 colorDrawable has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @NonNull
                              public static Drawable colorDrawable(@NonNull final Context context, @NonNull final Drawable drawable, @ColorInt final int color) {
                                  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable) {
                                      return colorVectorDrawable((VectorDrawable) drawable, color);
                                  }

                          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

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

                                  if (!shouldFade) {
                                      // no fading, add all applicable states
                                      states.addState(clickedState, clickedDrawable); // !
                                      states.addState(selectedState, focusedDrawable); // reuse the focused drawable
                                      states.addState(focusedState, focusedDrawable);
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 560..577
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 803..820

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

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

                                  if (!shouldFade) {
                                      // no fading, add all applicable states
                                      states.addState(clickedStates, clickedState); // !
                                      states.addState(selectedStates, checkedState);
                                      states.addState(focusedStates, normalState);
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 560..577
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 746..763

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

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

                                  if (!shouldFade) {
                                      // no fading, add all applicable states
                                      states.addState(clickedState, clickedDrawable); // !
                                      states.addState(selectedState, focusedDrawable); // reuse the focused drawable
                                      states.addState(focusedState, focusedDrawable);
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 746..763
                          sillyandroid/src/main/java/me/angrybyte/sillyandroid/extras/Coloring.java on lines 803..820

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

                          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