konvajs/konva

View on GitHub
src/Shape.ts

Summary

Maintainability
F
5 days
Test Coverage

File Shape.ts has 785 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Konva } from './Global';
import { Transform, Util } from './Util';
import { Factory } from './Factory';
import { Node, NodeConfig } from './Node';
import {
Severity: Major
Found in src/Shape.ts - About 1 day to fix

    Shape has 31 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Shape<
      Config extends ShapeConfig = ShapeConfig
    > extends Node<Config> {
      _centroid: boolean;
      colorKey: string;
    Severity: Minor
    Found in src/Shape.ts - About 3 hrs to fix

      Function drawScene has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas) {
          // basically there are 3 drawing modes
          // 1 - simple drawing when nothing is cached.
          // 2 - when we are caching current
          // 3 - when node is cached and we need to draw it into layer
      Severity: Major
      Found in src/Shape.ts - About 2 hrs to fix

        Function drawScene has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas) {
            // basically there are 3 drawing modes
            // 1 - simple drawing when nothing is cached.
            // 2 - when we are caching current
            // 3 - when node is cached and we need to draw it into layer
        Severity: Minor
        Found in src/Shape.ts - 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 drawHitFromCache has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          drawHitFromCache(alphaThreshold = 0) {
            var cachedCanvas = this._getCanvasCache(),
              sceneCanvas = this._getCachedSceneCanvas(),
              hitCanvas = cachedCanvas.hit,
              hitContext = hitCanvas.getContext(),
        Severity: Minor
        Found in src/Shape.ts - About 1 hr to fix

          Function drawHit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            drawHit(can?: HitCanvas, top?: Node, skipDragCheck = false) {
              if (!this.shouldDrawHit(top, skipDragCheck)) {
                return this;
              }
          
          
          Severity: Minor
          Found in src/Shape.ts - About 1 hr to fix

            Function getClientRect has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              getClientRect(config: ShapeGetClientRectConfig = {}) {
                const skipTransform = config.skipTransform;
            
                const relativeTo = config.relativeTo;
            
            
            Severity: Minor
            Found in src/Shape.ts - About 1 hr to fix

              Function __getFillPattern has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                __getFillPattern() {
                  if (this.fillPatternImage()) {
                    var ctx = getDummyContext();
                    const pattern = ctx.createPattern(
                      this.fillPatternImage(),
              Severity: Minor
              Found in src/Shape.ts - About 1 hr to fix

                Function drawHit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  drawHit(can?: HitCanvas, top?: Node, skipDragCheck = false) {
                    if (!this.shouldDrawHit(top, skipDragCheck)) {
                      return this;
                    }
                
                
                Severity: Minor
                Found in src/Shape.ts - About 45 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 __getFillPattern has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  __getFillPattern() {
                    if (this.fillPatternImage()) {
                      var ctx = getDummyContext();
                      const pattern = ctx.createPattern(
                        this.fillPatternImage(),
                Severity: Minor
                Found in src/Shape.ts - 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

                Function getClientRect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  getClientRect(config: ShapeGetClientRectConfig = {}) {
                    const skipTransform = config.skipTransform;
                
                    const relativeTo = config.relativeTo;
                
                
                Severity: Minor
                Found in src/Shape.ts - About 25 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 _useBufferCanvas has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  _useBufferCanvas(forceFill?: boolean): boolean {
                    // image and sprite still has "fill" as image
                    // so they use that method with forced fill
                    // it probably will be simpler, then copy/paste the code
                
                
                Severity: Minor
                Found in src/Shape.ts - About 25 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

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

                    if (cachedCanvas) {
                      context.save();
                
                      var m = this.getAbsoluteTransform(top).getMatrix();
                      context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
                Severity: Major
                Found in src/Shape.ts and 1 other location - About 3 hrs to fix
                src/Shape.ts on lines 669..678

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

                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

                    if (cachedHitCanvas) {
                      context.save();
                
                      var m = this.getAbsoluteTransform(top).getMatrix();
                      context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
                Severity: Major
                Found in src/Shape.ts and 1 other location - About 3 hrs to fix
                src/Shape.ts on lines 594..602

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

                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

                      for (var n = 0; n < colorStops.length; n += 2) {
                        grd.addColorStop(colorStops[n] as number, colorStops[n + 1] as string);
                      }
                Severity: Major
                Found in src/Shape.ts and 2 other locations - About 1 hr to fix
                src/Context.ts on lines 884..886
                src/Shape.ts on lines 328..330

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

                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

                      for (var n = 0; n < colorStops.length; n += 2) {
                        grd.addColorStop(colorStops[n] as number, colorStops[n + 1] as string);
                      }
                Severity: Major
                Found in src/Shape.ts and 2 other locations - About 1 hr to fix
                src/Context.ts on lines 884..886
                src/Shape.ts on lines 301..303

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

                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

                      this.shadowEnabled() &&
                      this.shadowOpacity() !== 0 &&
                      !!(
                        this.shadowColor() ||
                        this.shadowBlur() ||
                Severity: Minor
                Found in src/Shape.ts and 1 other location - About 35 mins to fix
                src/Shape.ts on lines 374..380

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

                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

                          this.fillEnabled() &&
                          !!(
                            this.fill() ||
                            this.fillPatternImage() ||
                            this.fillLinearGradientColorStops() ||
                Severity: Minor
                Found in src/Shape.ts and 1 other location - About 35 mins to fix
                src/Shape.ts on lines 238..245

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

                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