Chocobozzz/PeerTube

View on GitHub
client/src/app/shared/shared-main/date/from-now.pipe.ts

Summary

Maintainability
B
4 hrs
Test Coverage

Function transform has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  transform (arg: number | Date | string) {
    const argDate = new Date(arg)
    const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000)

    let interval = Math.floor(seconds / 31536000)
Severity: Minor
Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 1 hr to fix

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

      transform (arg: number | Date | string) {
        const argDate = new Date(arg)
        const seconds = Math.floor((Date.now() - argDate.getTime()) / 1000)
    
        let interval = Math.floor(seconds / 31536000)
    Severity: Minor
    Found in client/src/app/shared/shared-main/date/from-now.pipe.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

        if (interval >= 1) return $localize`${interval} min ago`
    Severity: Major
    Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return formatICU($localize`{interval, plural, =1 {1 week ago} other {{interval} weeks ago}}`, { interval })
      Severity: Major
      Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return formatICU($localize`{interval, plural, =1 {1 hour ago} other {{interval} hours ago}}`, { interval })
        Severity: Major
        Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return formatICU($localize`{interval, plural, =1 {1 day ago} other {{interval} days ago}}`, { interval })
          Severity: Major
          Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return $localize`just now`
            Severity: Major
            Found in client/src/app/shared/shared-main/date/from-now.pipe.ts - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status