zammad/zammad

View on GitHub
app/frontend/shared/utils/files.ts

Summary

Maintainability
D
1 day
Test Coverage

Function compressImage has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

export const compressImage = (
  imageSrc: string,
  type: string,
  options?: CompressOptions,
) => {
Severity: Minor
Found in app/frontend/shared/utils/files.ts - About 4 hrs 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 compressImage has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const compressImage = (
  imageSrc: string,
  type: string,
  options?: CompressOptions,
) => {
Severity: Major
Found in app/frontend/shared/utils/files.ts - About 2 hrs to fix

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

      const promise = new Promise<string>((resolve) => {
        img.onload = () => {
          const {
            x: imgX = 'auto',
            y: imgY = 'auto',
    Severity: Major
    Found in app/frontend/shared/utils/files.ts - About 2 hrs to fix

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

          img.onload = () => {
            const {
              x: imgX = 'auto',
              y: imgY = 'auto',
              quality = 'auto',
      Severity: Major
      Found in app/frontend/shared/utils/files.ts - About 2 hrs to fix

        Function loadImageIntoBase64 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        export const loadImageIntoBase64 = async (
          src: string,
          type?: string,
          alt?: string,
        ): Promise<string | null> => {
        Severity: Minor
        Found in app/frontend/shared/utils/files.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

        Avoid too many return statements within this function.
        Open

          return 0.6
        Severity: Major
        Found in app/frontend/shared/utils/files.ts - About 30 mins to fix

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

          const getQuality = (x: number, y: number) => {
            if (x < 200 && y < 200) return 1
            if (x < 400 && y < 400) return 0.9
            if (x < 600 && y < 600) return 0.8
            if (x < 900 && y < 900) return 0.7
          Severity: Minor
          Found in app/frontend/shared/utils/files.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

          There are no issues that match your filters.

          Category
          Status