Coursemology/coursemology2

View on GitHub
client/app/bundles/course/assessment/submission/components/ScribingView/ScribingCanvas.jsx

Summary

Maintainability
D
2 days
Test Coverage

ScribingCanvas has 37 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class ScribingCanvas extends Component {
  constructor(props) {
    super(props);

    this.line = undefined;

Function shouldComponentUpdate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  shouldComponentUpdate(nextProps) {
    if (this.canvas) {
      this.canvas.isDrawingMode = nextProps.scribing.isDrawingMode;
      this.canvas.freeDrawingBrush.color =
        nextProps.scribing.colors[scribingToolColor.DRAW];

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

  initializeCanvas(answerId, imageUrl) {
    this.image = new Image();
    this.image.src = imageUrl;

    this.image.onload = () => {

Function shouldComponentUpdate has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  shouldComponentUpdate(nextProps) {
    if (this.canvas) {
      this.canvas.isDrawingMode = nextProps.scribing.isDrawingMode;
      this.canvas.freeDrawingBrush.color =
        nextProps.scribing.colors[scribingToolColor.DRAW];

Function onload has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    this.image.onload = () => {
      // Get the calculated width of canvas, 800 is min width for scribing toolbar
      const element = document.getElementById(`canvas-${answerId}`);
      const maxWidth = Math.max(element.getBoundingClientRect().width, 800);

Avoid deeply nested control flow statements.
Open

            if (this.ellipse && this.ellipse.type === 'ellipse') {
              this.ellipse.selectable = false;
            }

Avoid deeply nested control flow statements.
Open

            if (this.rect && this.rect.type === 'rect') {
              this.rect.selectable = false;
            }

There are no issues that match your filters.

Category
Status