Chocobozzz/PeerTube

View on GitHub
server/core/middlewares/validators/shared/videos.ts

Summary

Maintainability
B
4 hrs
Test Coverage

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

export async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') {
  const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined

  const video = await loadVideo(id, fetchType, userId)

Severity: Minor
Found in server/core/middlewares/validators/shared/videos.ts - About 1 hr to fix

    Function checkCanSeeUserAuthVideo has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    export async function checkCanSeeUserAuthVideo (options: {
      req: Request
      res: Response
      video: MVideoId | MVideoWithRights
    }) {
    Severity: Minor
    Found in server/core/middlewares/validators/shared/videos.ts - About 55 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 checkUserCanManageVideo has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    export function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRightType, res: Response, onlyOwned = true) {
    Severity: Minor
    Found in server/core/middlewares/validators/shared/videos.ts - About 35 mins to fix

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

      export async function checkCanSeePasswordProtectedVideo (options: {
        req: Request
        res: Response
        video: MVideo
      }) {
      Severity: Minor
      Found in server/core/middlewares/validators/shared/videos.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 fail()
      Severity: Major
      Found in server/core/middlewares/validators/shared/videos.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            if (canUserAccessVideo(user, videoWithRights, UserRight.SEE_ALL_VIDEOS)) return true
        Severity: Major
        Found in server/core/middlewares/validators/shared/videos.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

            return fail()
          Severity: Major
          Found in server/core/middlewares/validators/shared/videos.ts - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status