Chocobozzz/PeerTube

View on GitHub
server/core/controllers/api/config.ts

Summary

Maintainability
F
3 days
Test Coverage

Function customConfig has 234 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function customConfig (): CustomConfig {
  return {
    instance: {
      name: CONFIG.INSTANCE.NAME,
      shortDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
Severity: Major
Found in server/core/controllers/api/config.ts - About 1 day to fix

    File config.ts has 418 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import express from 'express'
    import { remove, writeJSON } from 'fs-extra/esm'
    import snakeCase from 'lodash-es/snakeCase.js'
    import validator from 'validator'
    import { ServerConfigManager } from '@server/lib/server-config-manager.js'
    Severity: Minor
    Found in server/core/controllers/api/config.ts - About 6 hrs to fix

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

      function convertCustomConfigBody (body: CustomConfig) {
        function keyConverter (k: string) {
          // Transcoding resolutions exception
          if (/^\d{3,4}p$/.exec(k)) return k
          if (k === '0p') return k
      Severity: Minor
      Found in server/core/controllers/api/config.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

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

          search: {
            remoteUri: {
              users: CONFIG.SEARCH.REMOTE_URI.USERS,
              anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
            },
      Severity: Major
      Found in server/core/controllers/api/config.ts and 1 other location - About 4 hrs to fix
      server/core/lib/server-config-manager.ts on lines 115..126

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

      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

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

          export: {
            users: {
              enabled: CONFIG.EXPORT.USERS.ENABLED,
              exportExpiration: CONFIG.EXPORT.USERS.EXPORT_EXPIRATION,
              maxUserVideoQuota: CONFIG.EXPORT.USERS.MAX_USER_VIDEO_QUOTA
      Severity: Major
      Found in server/core/controllers/api/config.ts and 1 other location - About 1 hr to fix
      server/core/lib/server-config-manager.ts on lines 211..217

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

      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

          trending: {
            videos: {
              algorithms: {
                enabled: CONFIG.TRENDING.VIDEOS.ALGORITHMS.ENABLED,
                default: CONFIG.TRENDING.VIDEOS.ALGORITHMS.DEFAULT
      Severity: Major
      Found in server/core/controllers/api/config.ts and 1 other location - About 1 hr to fix
      server/core/lib/server-config-manager.ts on lines 306..313

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

      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

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

          broadcastMessage: {
            enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
            message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
            level: CONFIG.BROADCAST_MESSAGE.LEVEL,
            dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
      Severity: Major
      Found in server/core/controllers/api/config.ts and 1 other location - About 1 hr to fix
      server/core/lib/server-config-manager.ts on lines 288..293

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

      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

      configRouter.post('/instance-banner/pick',
        authenticate,
        createReqFiles([ 'bannerfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT),
        ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
        updateBannerValidator,
      Severity: Minor
      Found in server/core/controllers/api/config.ts and 1 other location - About 55 mins to fix
      server/core/controllers/api/config.ts on lines 86..92

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

      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

      configRouter.post('/instance-avatar/pick',
        authenticate,
        createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT),
        ensureUserHasRight(UserRight.MANAGE_CONFIGURATION),
        updateAvatarValidator,
      Severity: Minor
      Found in server/core/controllers/api/config.ts and 1 other location - About 55 mins to fix
      server/core/controllers/api/config.ts on lines 70..76

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

      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 3 locations. Consider refactoring.
      Open

          followers: {
            instance: {
              enabled: CONFIG.FOLLOWERS.INSTANCE.ENABLED,
              manualApproval: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL
            }
      Severity: Minor
      Found in server/core/controllers/api/config.ts and 2 other locations - About 35 mins to fix
      server/core/controllers/misc.ts on lines 103..108
      server/core/lib/server-config-manager.ts on lines 299..304

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

      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