spritejs/sprite-core

View on GitHub
src/core/basesprite.js

Summary

Maintainability
F
3 days
Test Coverage

File basesprite.js has 735 lines of code (exceeds 350 allowed). Consider refactoring.
Open

import {Matrix, Vector} from 'sprite-math';
import {Timeline} from 'sprite-animator';
import {flow, absolute, rectVertices, deprecate, drawRadiusBox, findColor, cacheContextPool} from '../utils';
import BaseAttr from './baseattr';
import BaseNode from './basenode';
Severity: Major
Found in src/core/basesprite.js - About 1 day to fix

    Function draw has 75 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

      draw(t, drawingContext = this.context) { // eslint-disable-line complexity
        super.draw(t, drawingContext);
    
        if(!this.isVisible()) {
          return;
    Severity: Major
    Found in src/core/basesprite.js - About 2 hrs to fix

      Function draw has a Cognitive Complexity of 34 (exceeds 25 allowed). Consider refactoring.
      Open

        draw(t, drawingContext = this.context) { // eslint-disable-line complexity
          super.draw(t, drawingContext);
      
          if(!this.isVisible()) {
            return;
      Severity: Minor
      Found in src/core/basesprite.js - 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

      Function drawDot9Image has 67 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      function drawDot9Image(drawingContext, image, clip9, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight) {
        const w = image.width,
          h = image.height;
      
        const [top, right, bottom, left] = clip9 || [16, 16, 16, 16];
      Severity: Major
      Found in src/core/basesprite.js - About 1 hr to fix

        Function render has 53 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

          render(t, drawingContext) {
            const border = this.attr('border'),
              borderRadius = this.attr('borderRadius'),
              padding = this.attr('padding'),
              [offsetWidth, offsetHeight] = this.offsetSize,
        Severity: Major
        Found in src/core/basesprite.js - About 1 hr to fix

          Function drawBgImage has a Cognitive Complexity of 29 (exceeds 25 allowed). Consider refactoring.
          Open

          function drawBgImage(drawingContext, bgimage, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight) {
            const {image, display, clip9} = bgimage;
          
            if(display === '.9') {
              drawDot9Image(drawingContext, image, clip9, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight);
          Severity: Minor
          Found in src/core/basesprite.js - About 55 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

          Function drawDot9Image has 8 arguments (exceeds 5 allowed). Consider refactoring.
          Open

          function drawDot9Image(drawingContext, image, clip9, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight) {
          Severity: Major
          Found in src/core/basesprite.js - About 50 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      while(ch > borderWidth) {
                        drawingContext.drawImage(image, clientWidth - cw, clientHeight - ch, w, h);
                        ch -= h;
                      }
            Severity: Major
            Found in src/core/basesprite.js - About 45 mins to fix

              Function drawBgImage has 7 arguments (exceeds 5 allowed). Consider refactoring.
              Open

              function drawBgImage(drawingContext, bgimage, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight) {
              Severity: Major
              Found in src/core/basesprite.js - About 45 mins to fix

                Consider simplifying this complex logical expression.
                Open

                      if(bgimage && bgimage.display !== 'none' || borderRadius && (this.nodeType !== 'sprite' || this.textures && this.textures.length)) {
                        drawingContext.clip();
                      }
                Severity: Major
                Found in src/core/basesprite.js - About 40 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                      if(!this.cacheContext || borderWidth || borderRadius || bgcolor || bgimage && bgimage.display !== 'none') {
                        let [x, y, w, h, r] = [borderWidth, borderWidth,
                          clientWidth, clientHeight,
                          borderRadius];
                  
                  
                  Severity: Major
                  Found in src/core/basesprite.js - About 40 mins to fix

                    Function drawDot9Image has a Cognitive Complexity of 27 (exceeds 25 allowed). Consider refactoring.
                    Open

                    function drawDot9Image(drawingContext, image, clip9, borderWidth, offsetWidth, offsetHeight, clientWidth, clientHeight) {
                      const w = image.width,
                        h = image.height;
                    
                      const [top, right, bottom, left] = clip9 || [16, 16, 16, 16];
                    Severity: Minor
                    Found in src/core/basesprite.js - 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

                    Avoid too many return statements within this function.
                    Open

                          return false;
                    Severity: Major
                    Found in src/core/basesprite.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return true;
                      Severity: Major
                      Found in src/core/basesprite.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return this.parent.isVisible();
                        Severity: Major
                        Found in src/core/basesprite.js - About 30 mins to fix

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

                          const _animations = Symbol('animations'),
                            _cachePriority = Symbol('cachePriority'),
                            _effects = Symbol('effects'),
                            _flow = Symbol('flow'),
                            _releaseKeys = Symbol('releaseKeys');
                          Severity: Minor
                          Found in src/core/basesprite.js and 2 other locations - About 35 mins to fix
                          src/core/attr.js on lines 3..7
                          src/modules/actions/node.js on lines 21..25

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

                          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