konvajs/konva

View on GitHub
src/shapes/Path.ts

Summary

Maintainability
F
1 wk
Test Coverage

File Path.ts has 774 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { _registerNode } from '../Global';

import { GetSet, PathSegment } from '../types';
Severity: Major
Found in src/shapes/Path.ts - About 1 day to fix

    Function parsePathData has 277 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static parsePathData(data): PathSegment[] {
        // Path Data Segment must begin with a moveTo
        //m (x y)+  Relative moveTo (subsequent points are treated as lineTo)
        //M (x y)+  Absolute moveTo (subsequent points are treated as lineTo)
        //l (x y)+  Relative lineTo
    Severity: Major
    Found in src/shapes/Path.ts - About 1 day to fix

      Function parsePathData has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
      Open

        static parsePathData(data): PathSegment[] {
          // Path Data Segment must begin with a moveTo
          //m (x y)+  Relative moveTo (subsequent points are treated as lineTo)
          //M (x y)+  Absolute moveTo (subsequent points are treated as lineTo)
          //l (x y)+  Relative lineTo
      Severity: Minor
      Found in src/shapes/Path.ts - About 1 day 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 getSelfRect has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        getSelfRect() {
          var points: Array<number> = [];
          this.dataArray.forEach(function (data) {
            if (data.command === 'A') {
              // Approximates by breaking curve into line segments
      Severity: Major
      Found in src/shapes/Path.ts - About 3 hrs to fix

        Function getPointAtLengthOfDataArray has 75 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static getPointAtLengthOfDataArray(length: number, dataArray) {
            var point,
              i = 0,
              ii = dataArray.length;
        
        
        Severity: Major
        Found in src/shapes/Path.ts - About 3 hrs to fix

          Function calcLength has 73 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static calcLength(x, y, cmd, points) {
              var len, p1, p2, t;
              var path = Path;
          
              switch (cmd) {
          Severity: Major
          Found in src/shapes/Path.ts - About 2 hrs to fix

            Function convertEndpointToCenterParameterization has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static convertEndpointToCenterParameterization(
                x1,
                y1,
                x2,
                y2,
            Severity: Major
            Found in src/shapes/Path.ts - About 2 hrs to fix

              Function _sceneFunc has 50 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _sceneFunc(context) {
                  var ca = this.dataArray;
              
                  // context position
                  context.beginPath();
              Severity: Minor
              Found in src/shapes/Path.ts - About 2 hrs to fix

                Function _sceneFunc has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                  _sceneFunc(context) {
                    var ca = this.dataArray;
                
                    // context position
                    context.beginPath();
                Severity: Minor
                Found in src/shapes/Path.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 getPointOnLine has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?) {
                    if (fromX === undefined) {
                      fromX = P1x;
                    }
                    if (fromY === undefined) {
                Severity: Minor
                Found in src/shapes/Path.ts - About 1 hr to fix

                  Function calcLength has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    static calcLength(x, y, cmd, points) {
                      var len, p1, p2, t;
                      var path = Path;
                  
                      switch (cmd) {
                  Severity: Minor
                  Found in src/shapes/Path.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 convertEndpointToCenterParameterization has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                    static convertEndpointToCenterParameterization(
                      x1,
                      y1,
                      x2,
                      y2,
                  Severity: Minor
                  Found in src/shapes/Path.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

                  Avoid deeply nested control flow statements.
                  Open

                                for (var idx = ca.length - 2; idx >= 0; idx--) {
                                  if (ca[idx].command === 'M') {
                                    cpx = ca[idx].points[0] + dx;
                                    cpy = ca[idx].points[1] + dy;
                                    break;
                  Severity: Major
                  Found in src/shapes/Path.ts - About 45 mins to fix

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

                      static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX?, fromY?) {
                        if (fromX === undefined) {
                          fromX = P1x;
                        }
                        if (fromY === undefined) {
                    Severity: Minor
                    Found in src/shapes/Path.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

                    Avoid too many return statements within this function.
                    Open

                        return null;
                    Severity: Major
                    Found in src/shapes/Path.ts - About 30 mins to fix

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

                        static getPointAtLengthOfDataArray(length: number, dataArray) {
                          var point,
                            i = 0,
                            ii = dataArray.length;
                      
                      
                      Severity: Minor
                      Found in src/shapes/Path.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

                                case 't':
                                  ctlPtx = cpx;
                                  ctlPty = cpy;
                                  prevCmd = ca[ca.length - 1];
                                  if (prevCmd.command === 'Q') {
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 5 hrs to fix
                      src/shapes/Path.ts on lines 681..693

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

                      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

                                case 'T':
                                  ctlPtx = cpx;
                                  ctlPty = cpy;
                                  prevCmd = ca[ca.length - 1];
                                  if (prevCmd.command === 'Q') {
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 5 hrs to fix
                      src/shapes/Path.ts on lines 694..706

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

                      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

                              } else {
                                // counter-clockwise
                                for (t = start + inc; t < end; t += inc) {
                                  p2 = path.getPointOnEllipticalArc(
                                    points[0],
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 3 hrs to fix
                      src/shapes/Path.ts on lines 819..833

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

                      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 (dTheta < 0) {
                                // clockwise
                                for (t = start - inc; t > end; t -= inc) {
                                  p2 = path.getPointOnEllipticalArc(
                                    points[0],
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 3 hrs to fix
                      src/shapes/Path.ts on lines 833..847

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

                      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

                              } else {
                                // counter-clockwise
                                for (let t = start + inc; t < end; t += inc) {
                                  const point = Path.getPointOnEllipticalArc(
                                    data.points[0],
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 3 hrs to fix
                      src/shapes/Path.ts on lines 126..139

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

                      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 (dTheta < 0) {
                                // clockwise
                                for (let t = start - inc; t > end; t -= inc) {
                                  const point = Path.getPointOnEllipticalArc(
                                    data.points[0],
                      Severity: Major
                      Found in src/shapes/Path.ts and 1 other location - About 3 hrs to fix
                      src/shapes/Path.ts on lines 139..152

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

                      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

                          var y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
                      Severity: Minor
                      Found in src/shapes/Path.ts and 1 other location - About 50 mins to fix
                      src/shapes/Path.ts on lines 393..393

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

                      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

                          var x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
                      Severity: Minor
                      Found in src/shapes/Path.ts and 1 other location - About 50 mins to fix
                      src/shapes/Path.ts on lines 394..394

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

                      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

                          var cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
                      Severity: Minor
                      Found in src/shapes/Path.ts and 1 other location - About 35 mins to fix
                      src/shapes/Path.ts on lines 904..904

                      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

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

                          var cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
                      Severity: Minor
                      Found in src/shapes/Path.ts and 1 other location - About 35 mins to fix
                      src/shapes/Path.ts on lines 905..905

                      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