Bnei-Baruch/mdb

View on GitHub
api/handlers.go

Summary

Maintainability
F
1 wk
Test Coverage

File handlers.go has 1196 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package api

import (
    "database/sql"
    "encoding/hex"
Severity: Major
Found in api/handlers.go - About 2 days to fix

    Function handleInsert has a Cognitive Complexity of 112 (exceeds 20 allowed). Consider refactoring.
    Open

    func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
        r := input.(InsertRequest)
    
        log.Infof("Lookup file by SHA1")
        file, _, err := FindFileBySHA1(exec, r.File.Sha1)
    Severity: Minor
    Found in api/handlers.go - About 1 day 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 handleInsert has 258 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
        r := input.(InsertRequest)
    
        log.Infof("Lookup file by SHA1")
        file, _, err := FindFileBySHA1(exec, r.File.Sha1)
    Severity: Major
    Found in api/handlers.go - About 1 day to fix

      Function handleSend has 100 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
          r := input.(SendRequest)
      
          // Original
          original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
      Severity: Major
      Found in api/handlers.go - About 3 hrs to fix

        Function handleTranscode has 94 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
            r := input.(TranscodeRequest)
        
            if r.Message != "" {
                log.Infof("Transcode Error: %s", r.Message)
        Severity: Major
        Found in api/handlers.go - About 2 hrs to fix

          Function handleSend has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
          Open

          func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
              r := input.(SendRequest)
          
              // Original
              original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
          Severity: Minor
          Found in api/handlers.go - About 2 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 handleInsert has 25 return statements (exceeds 4 allowed).
          Open

          func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
              r := input.(InsertRequest)
          
              log.Infof("Lookup file by SHA1")
              file, _, err := FindFileBySHA1(exec, r.File.Sha1)
          Severity: Major
          Found in api/handlers.go - About 2 hrs to fix

            Function handleUpload has 72 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                r := input.(UploadRequest)
            
                log.Info("Creating operation")
                operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, nil)
            Severity: Minor
            Found in api/handlers.go - About 1 hr to fix

              Function handleConvert has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
              Open

              func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                  r := input.(ConvertRequest)
              
                  in, _, err := FindFileBySHA1(exec, r.Sha1)
                  if err != nil {
              Severity: Minor
              Found in api/handlers.go - About 1 hr 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 handleConvert has 59 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                  r := input.(ConvertRequest)
              
                  in, _, err := FindFileBySHA1(exec, r.Sha1)
                  if err != nil {
              Severity: Minor
              Found in api/handlers.go - About 1 hr to fix

                Function DescendantUnitsHandler has 59 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func DescendantUnitsHandler(c *gin.Context) {
                    mdb := c.MustGet("MDB").(*sql.DB)
                
                    f, _, err := FindFileBySHA1(mdb, c.Param("sha1"))
                    if err != nil {
                Severity: Minor
                Found in api/handlers.go - About 1 hr to fix

                  Function handleSend has 14 return statements (exceeds 4 allowed).
                  Open

                  func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                      r := input.(SendRequest)
                  
                      // Original
                      original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
                  Severity: Major
                  Found in api/handlers.go - About 1 hr to fix

                    Function handleUpload has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                        r := input.(UploadRequest)
                    
                        log.Info("Creating operation")
                        operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, nil)
                    Severity: Minor
                    Found in api/handlers.go - About 1 hr 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 handleTranscode has 13 return statements (exceeds 4 allowed).
                    Open

                    func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                        r := input.(TranscodeRequest)
                    
                        if r.Message != "" {
                            log.Infof("Transcode Error: %s", r.Message)
                    Severity: Major
                    Found in api/handlers.go - About 1 hr to fix

                      Function handleTranscode has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                          r := input.(TranscodeRequest)
                      
                          if r.Message != "" {
                              log.Infof("Transcode Error: %s", r.Message)
                      Severity: Minor
                      Found in api/handlers.go - About 1 hr 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 handleJoin has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func handleJoin(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                          r := input.(JoinRequest)
                      
                          // Fetch input files
                          inOriginals := make([]*models.File, 0)
                      Severity: Minor
                      Found in api/handlers.go - About 1 hr to fix

                        Function handleUpload has 10 return statements (exceeds 4 allowed).
                        Open

                        func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                            r := input.(UploadRequest)
                        
                            log.Info("Creating operation")
                            operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, nil)
                        Severity: Major
                        Found in api/handlers.go - About 1 hr to fix

                          Function handleReplace has 9 return statements (exceeds 4 allowed).
                          Open

                          func handleReplace(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                              r := input.(ReplaceRequest)
                          
                              opFiles := make([]*models.File, 0)
                          
                          
                          Severity: Major
                          Found in api/handlers.go - About 55 mins to fix

                            Function handleConvert has 8 return statements (exceeds 4 allowed).
                            Open

                            func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                                r := input.(ConvertRequest)
                            
                                in, _, err := FindFileBySHA1(exec, r.Sha1)
                                if err != nil {
                            Severity: Major
                            Found in api/handlers.go - About 50 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                          if err != nil {
                                              log.Errorf("Error describing content unit: %s", err.Error())
                                          }
                              Severity: Major
                              Found in api/handlers.go - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                            if r.Metadata == nil {
                                                return nil, nil, NewBadRequestError(errors.New("Metadata is required"))
                                            }
                                Severity: Major
                                Found in api/handlers.go - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                              if r.Metadata.FilmDate != nil {
                                                  filmDate = *r.Metadata.FilmDate
                                              }
                                  Severity: Major
                                  Found in api/handlers.go - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                if err != nil {
                                                    return nil, nil, errors.Wrap(err, "Create declamation content unit")
                                                }
                                    Severity: Major
                                    Found in api/handlers.go - About 45 mins to fix

                                      Function handleSirtutim has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func handleSirtutim(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                                          r := input.(SirtutimRequest)
                                      
                                          log.Info("Creating operation")
                                          operation, err := CreateOperation(exec, common.OP_SIRTUTIM, r.Operation, nil)
                                      Severity: Major
                                      Found in api/handlers.go - About 40 mins to fix

                                        Function handleTrim has 6 return statements (exceeds 4 allowed).
                                        Open

                                        func handleTrim(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                                            r := input.(TrimRequest)
                                        
                                            // Fetch parent files
                                            original, _, err := FindFileBySHA1(exec, r.OriginalSha1)
                                        Severity: Major
                                        Found in api/handlers.go - About 40 mins to fix

                                          Function handleJoin has 6 return statements (exceeds 4 allowed).
                                          Open

                                          func handleJoin(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                                              r := input.(JoinRequest)
                                          
                                              // Fetch input files
                                              inOriginals := make([]*models.File, 0)
                                          Severity: Major
                                          Found in api/handlers.go - About 40 mins to fix

                                            Function handleDemux has 5 return statements (exceeds 4 allowed).
                                            Open

                                            func handleDemux(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
                                                r := input.(DemuxRequest)
                                            
                                                parent, _, err := FindFileBySHA1(exec, r.Sha1)
                                                if err != nil {
                                            Severity: Major
                                            Found in api/handlers.go - About 35 mins to fix

                                              Function DescendantUnitsHandler has 5 return statements (exceeds 4 allowed).
                                              Open

                                              func DescendantUnitsHandler(c *gin.Context) {
                                                  mdb := c.MustGet("MDB").(*sql.DB)
                                              
                                                  f, _, err := FindFileBySHA1(mdb, c.Param("sha1"))
                                                  if err != nil {
                                              Severity: Major
                                              Found in api/handlers.go - About 35 mins to fix

                                                Function removeDescendants has 5 return statements (exceeds 4 allowed).
                                                Open

                                                func removeDescendants(exec boil.Executor, file *models.File) ([]events.Event, error) {
                                                    evnts := make([]events.Event, 0)
                                                    if file.RemovedAt.Valid {
                                                        return evnts, nil
                                                    }
                                                Severity: Major
                                                Found in api/handlers.go - About 35 mins to fix

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

                                                      if r.Proxy != nil {
                                                          proxy, _, err = FindFileBySHA1(exec, r.Proxy.Sha1)
                                                          if err != nil {
                                                              return nil, nil, errors.Wrap(err, "Lookup proxy file")
                                                          }
                                                  Severity: Major
                                                  Found in api/handlers.go and 1 other location - About 2 hrs to fix
                                                  api/handlers.go on lines 457..475

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

                                                  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

                                                      if r.Source != nil {
                                                          source, _, err = FindFileBySHA1(exec, r.Source.Sha1)
                                                          if err != nil {
                                                              return nil, nil, errors.Wrap(err, "Lookup source file")
                                                          }
                                                  Severity: Major
                                                  Found in api/handlers.go and 1 other location - About 2 hrs to fix
                                                  api/handlers.go on lines 435..453

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

                                                  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

                                                      if r.Proxy != nil {
                                                          log.Info("Creating proxy")
                                                          props = map[string]interface{}{
                                                              "duration": r.Proxy.Duration,
                                                          }
                                                  Severity: Minor
                                                  Found in api/handlers.go and 1 other location - About 40 mins to fix
                                                  api/handlers.go on lines 1243..1255

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

                                                  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

                                                      if r.Proxy != nil {
                                                          log.Info("Creating joined proxy")
                                                          props = map[string]interface{}{
                                                              "duration": r.Proxy.Duration,
                                                          }
                                                  Severity: Minor
                                                  Found in api/handlers.go and 1 other location - About 40 mins to fix
                                                  api/handlers.go on lines 333..345

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

                                                  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